[Tutor] Conditional output of a header line
Levy Lazarre
llazarre@yahoo.com
Tue, 24 Sep 2002 12:37:40 -0700 (PDT)
Good afternoon all,
I have written a script that cleans an error log and
writes the output to a
new file. Basically, I read the file line by line,
apply various filters to
eliminate the trashy lines, and output the desired
lines to a new file via
print statements. I am having some difficulty with one
last task however.
I need to conditionally eliminate a header line
depending on what comes on
the next line.
Please see the sample below. When a line starts with
"Console Log" I need to
'look ahead' and see if it is followed by a time stamp
hh:mm:ss. If so,
output it. If not suppress it. In the example
enclosed, I would want to output
the first "Console Log ..." line but ignore the second
one.
Is there an easy way to do this in Python? Apparently
I can't use a regexp
since I am reading line by line. All suggestions
(except coding a state
machine!) will be appreciated.
Thanks,
Levy Lazarre
Integration Coordinator
Mid-Florida Medical Services
------------------------------sample-----------------------------------------
Console Log for 09/20/02 - Messages starting 3466 of
4238
16:25:58 I/B ORDER/RES - Test Code Invalid For
Specified CLINSTAR PATIENT CARE Order...Data
Discarded! 1625
.
.
.
Console Log for 09/21/02 - Messages starting 2797 of
3826
E Order...Data Discarded! 0925
.
.
.
__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com