[Tutor] Matching on multiple log lines
Matthew Warren
Matthew.Warren at Digica.com
Mon Oct 30 17:26:58 CET 2006
> -----Original Message-----
> From: tutor-bounces at python.org
> [mailto:tutor-bounces at python.org] On Behalf Of Kent Johnson
> Sent: 30 October 2006 11:55
> Cc: tutor at python.org
> Subject: Re: [Tutor] Matching on multiple log lines
>
> wesley chun wrote:
> >> 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?
> >
> >
> > just throwing this out there... would anyone do something like a
> > open('log.txt', 'w').write(str(len(re.split(r'Writing Message
> > to([\w\d\s:/\.]+?)TRANSPORT_STREAM_ID Parameter value:
> > 0160\r?\n'))), or is this unseemly due the fact that the file may be
> > very large?
>
> If the log file can be read into memory then a regex-based solution
> might work well though your code looks a bit scrambled to me. Rather
> than re.split() I would use re.findall().
>
> To solve this line-by-line I would make a simple state machine that
> looks for lines of interest and moves through the states Begin,
> Found_Transport_Stream_Id and Found_Writing_Message.
>
> Kent
Exactly how I have solved this in the past writing a general purpose
tool for scanning logs for things. More code, but much easier to follow.
--
[BEGIN silly disclaimer]
This email is confidential and may be privileged. If you are not the intended recipient please notify the sender immediately and delete the email from your computer.
You should not copy the email, use it for any purpose or disclose its contents to any other person.
Please note that any views or opinions presented in this email may be personal to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence of viruses. Digica accepts no liability for any damage caused by any virus transmitted by this email.
UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com
SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com
More information about the Tutor
mailing list