[Tutor] Matching on multiple log lines
jim stockford
jim at well.com
Sun Oct 29 03:04:53 CET 2006
so it's guaranteed that
'Writing Message to'
will always be followed by
'TRANSPORT_STREAM_ID'
before the next occurrence of
'Writing Message to'
and all text between can be ignored,
and we increment the counter if and only if
there is a newline immediately after
'TRANSPORT_STREAM_ID'
yes?
I.e. in your example, log, while there are two
'Writing Message to'
blah blah
'TRANSPORT_STREAM_ID'
sequences, only one has the required newline
and proper counting increments the counter
just once, yes?
I'd keep a line counter to record the total number
of lines read.
I'd use a boolean flag to record the occurrence of
'Writing Message to'
If flag is TRUE and if
'TRANSPORT_STREAM_ID'
then test for newline
and if TRUE
then add the line number to a list of line numbers for
the newline
then reset flag to FALSE
and resume testing down the file.
when all done, save the line number of the very last
line in the logfile to a stash file.
upon next read-through, read the line number of
the last line from the stash file and blindly read and
discard that many lines before resuming the process.
maybe a good idea to save not only the last line
number but also the line itself into the stash file and
after dropping to the line of the last number , compare
text--call police if no match.
On Oct 28, 2006, at 5:55 PM, Tom Tucker wrote:
> I would appreciate any recommendations or assistance on how to read
> and parse this log. The log is constantly growing and has the
> potential of being large. For this reason, we are reading in line by
> line. How do I match on multiple lines, while reading a log line by
> line. Hopefully the logic example and sample log will make more
> sense.
> Thank you,
>
>
> Logic:
> ------
> 1) Search for this string 'Writing Message to'
> 2) Search ahead for this string 'TRANSPORT_STREAM_ID'
> 3) Followed by a blank line
> 4) If 1,2, and 3: increase a counter or something (counter +=1)
> 4) Repeat process
>
>
> Example log
> ############
> 2006/10/24 20:46:05.853 Writing Message to 192.168.1.1:3211
> Protocol: 2
> Message Type: PROVISION
> Parameters:
> Parameter type: CHANNEL_ID Parameter value: 0001
> Parameter type: SCG_ID Parameter value: 0001
> Parameter type: TRANSPORT_STREAM_ID Parameter value: 0160
> Parameter type: PROGRAM_NUMBER Parameter value: 0001
> Parameter type: GROUP Parameter value: 0009 0002
> 2006/10/24 20:46:05.957 Receiving message from 192.168.1.1:3211
> 2006/10/24 20:47:05.011 Writing Message to 192.168.1.2:3211
> Protocol: 2
> Message Type: PROVISION
> Parameters:
> Parameter type: CHANNEL_ID Parameter value: 0001
> Parameter type: SCG_ID Parameter value: 0001
> Parameter type: TRANSPORT_STREAM_ID Parameter value: 0160
>
> 2006/10/24 20:47:05.057 Blah Blah..more logging
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list