Apr-22-2020, 09:25 PM
Here is the code.
It prints all lines (the ones I'm looking for) but I do not need all lines.
I need to print only the last match of "the second line that is LotComplete" for each "first line that is -- InitializeRequest ".
Do you know how to do that?
Thank you.
It prints all lines (the ones I'm looking for) but I do not need all lines.
I need to print only the last match of "the second line that is LotComplete" for each "first line that is -- InitializeRequest ".
Do you know how to do that?
Thank you.
import os import re lstr = '-- InitializeRequest' lt_nd = '-- LotComplete' ltend = '' hand_f = '\\somelog.txt' with open(hand_f) as apse: for rn_l in apse: rn_l= rn_l.rstrip() #print (rn_l) if lstr in rn_l : #print (rn_l) rn_l = rn_l.replace('[','').replace(']','') st1,*extraWords, = rn_l.split('-') print ("Lot Start-->> ", st1,'\n') if lt_nd in rn_l : rn_l = rn_l.replace('[','').replace(']','') st2,*extraWords, = rn_l.split('-') print("LotComplete -->> ", st2, '\n')