jeudi 4 mai 2017

Print string "Image" along with matching pattern in the text file in Python

I am new to python.My text file has the below information

15:50:12 RECID: C642 SORD=000000000 Image=000000001
15:50:12 STEP 2: BUILD ICC KEY MAINTENANCE
15:50:12 RECID: C642 Image=000000000 EORD=000000007
15:50:12 STEP 3: COUNT OF RECORDS UDPATED
02:26:12 CPSE0152E 02.26.13 IS-0001 SS-BSS  SSU-BSS  SE-008965 Image -UE027A0
02:26:12 010000A ABC-HS52                                                 
02:26:12 HS52    DEF-hs52            

Line 5 (02:26:12) will contain “SE-“ and "Image"-XXXXXXX” where XXXXXXX=type of Image dump as coded. The next line will have “ABC-XXXX” where XXXX = segment name Line 3 should have “DEF-XXXX” . We only need these 3 lines.

"Image" keyword can occure so many places but I want to search the "Image" name along with the next line have information “ABC-XXXX” and “DEF-XXXX” and print the next 2 lines of the text

my output should be

02:26:12 CPSE0152E 02.26.13 IS-0001 SS-BSS  SSU-BSS  SE-008965 Image-UE027A0
02:26:12 010000A ABC-HS52                                                 
02:26:12 HS52    DEF-hs52  

Aucun commentaire:

Enregistrer un commentaire