[Tutor] Logfile Manipulation

Kent Johnson kent37 at tds.net
Mon Nov 9 12:54:58 CET 2009


On Mon, Nov 9, 2009 at 4:36 AM, Stephen Nelson-Smith <sanelson at gmail.com> wrote:
>>>>I want to extract 24 hrs of data based timestamps like this:
>>>>
>>>> [04/Nov/2009:04:02:10 +0000]
>>>
>>> OK It looks like you could use a regex to extract the first
>>> thing you find between square brackets. Then convert that to a time.
>>
>> I'm currently thinking I can just use a string comparison after the
>> first entry for the day - that saves date arithmetic.

As long as the times are all in the same time zone.

>> How do I handle concurrency?  I have 6 log files which I need to turn
>> into one time-sequenced log.
>>
>> I guess I need to switch between each log depending on whether the
>> next entry is the next chronological entry between all six.  Then on a
>> per line basis I can also reject it if it matches the stuff I want to
>> throw out, and substitute it if I need to, then write out to the new
>> file.

If you create iterators from the files that yield (timestamp, entry)
pairs, you can merge the iterators using one of these recipes:
http://code.activestate.com/recipes/491285/
http://code.activestate.com/recipes/535160/

Kent


More information about the Tutor mailing list