Apr-07-2019, 03:02 AM
Goal: If I find "FP-X" in the string below, I need to retrieve the string on the left of "FP-X" label.
Like retrieve in this example "0/1/CPU0", "0/5/CPU0" and "5/6/CPU0". I attempted to convert this into a list to let me manipulate elements, but no luck.
Like retrieve in this example "0/1/CPU0", "0/5/CPU0" and "5/6/CPU0". I attempted to convert this into a list to let me manipulate elements, but no luck.
string = " 0/1/CPU0 FP-X 40-10GbE IOS XR RUN PWR,NSHUT,MON 0/5/CPU0 FP-X 40-10GbE IOS XR RUN PWR,NSHUT,MON 0/9/CPU0 FP-140G 14-10GbE IOS XR RUN PWR,NSHUT,MON 5/6/CPU0 FP-X 40-10GbE IOS XR RUN PWR,NSHUT,MON " #I confirm this is indeed a 'string' type: print(type(string))Output result is:
Output:<class 'str'>
#Then I attempt to convert into list: list_data = [string] #I confirm this is now a list: print(type(list_data)) Output result below is:
Output:<class 'list'>
#Problem:Then I see the output and I don't see it is converted into a list (there is no '' between elements). print(list_data)
Output:[' platform \r\n\rSat Apr 6 21:38:00.782 EST\r\nNode Type PLIM State Config State\r\n------------- ----------------- ------------------ --------------- ---------------\r\n0/0/CPU0 MSC-B 8-10GbE IOS XR RUN PWR,NSHUT,MON\r\n0/7/CPU0 FP-X 4-100GbE IOS XR RUN PWR,NSHUT,MON\r\n0/RP0/CPU0 RP(Active) N/A IOS XR RUN PWR,NSHUT,MON\r\n0/RP1/CPU0 RP(Standby) N/A IOS XR RUN PWR,NSHUT,MON\r\n1/0/CPU0 MSC-X 40-10GbE IOS XR RUN PWR,NSHUT,MON\r\n1/2/CPU0 MSC-X 40-10GbE IOS XR RUN PWR,NSHUT,MON\r\n1/3/CPU0 MSC Jacket Card IOS XR RUN PWR,NSHUT,MON\r\n1/3/0 MSC(SPA) 10X1GE OK PWR,NSHUT,MON\r\n1/RP0/CPU0 RP(Active) N/A IOS XR RUN PWR,NSHUT,MON\r\n1/RP1/CPU0 RP(Standby) N/A IOS XR RUN PWR,NSHUT,MON\r\nRP/0/RP0/CPU0:CRS-O#']