python - Is there a command choose where you want to start and stop parsing data in a text file? -
is there command (line or string) choose want start , stop parsing data of x in text file? there sort of string command read between specific parts of strings?
let's textfile is:
[6-1-14] data record [9:55:00am] [6-1-14] x=4, y=5 [9:55:00am] [6-1-14] x=3, y=4 [9:55:00am] [6-1-14] data stop [9:55:00am] [6-1-14] debug: start [9:55:00am] [6-1-14] x=4, y=5 [9:55:00am] [6-1-14] debug: end [9:55:00am] [6-2-14] data record [9:55:00am] [6-2-14] x=2, y=3 [9:55:00am] [6-2-14] x=1, y=2 [9:55:00am] [6-2-14] data stop [9:55:00am] [6-3-14] data record [9:55:00am] [6-3-14] x=0, y=1 [9:55:00am] [6-3-14] data stop [9:55:00am]
desired output: all values stored in list between data record , data stop. values between debug: start , debug: end should not recorded.
x =[4,3,2,1]
motive code: store values of x between strings data record , data stop , else.
assuming using python can like:
text = """ text above """ p1=0 output="" while true: p2 = text.find("data record",p1)+11 p3 = text.find("data stop", p1) if p2<0 or p3<0: break s = text[p2:p3] output +=s p1=p3+10 print output
which prints
[9:55:00am] [6-1-14] x=4, y=5 [9:55:00am] [6-1-14] x=3, y=4 [9:55:00am] [6-1-14] [9:55:00am] [6-2-14] x=2, y=3 [9:55:00am] [6-2-14] x=1, y=2 [9:55:00am] [6-2-14] [9:55:00am] [6-3-14] x=0, y=1 [9:55:00am] [6-3-14]
which bit between record , stop bits. parse that?
Comments
Post a Comment