Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Parsing a specific section of a log file

by been42 (Curate)
on Feb 28, 2007 at 22:00 UTC ( #602611=note: print w/ replies, xml ) Need Help??


in reply to Re: Parsing a specific section of a log file
in thread Parsing a specific section of a log file

Wow, I didn't know about File::ReadBackwards! I'll have to try that. Here's what I've been doing to parse an Apache error log at work that's never been rotated. I use a start date and an end date, but I think the same principle should apply to times.

use Tie::File; tie my @lines, 'Tie::File', 'error.log'; LINE: for (my $i=$#lines; $i >= 0; $i--) { my $d = substr($lines[$i], 1, 24); my $file_date = $time{"yyyy-mm-dd", ParseDate($d)}; next LINE if ($file_date gt $edate); last LINE if ($file_date lt $sdate); # process here }


Comment on Re^2: Parsing a specific section of a log file
Download Code
Re^3: Parsing a specific section of a log file
by jettero (Monsignor) on Feb 28, 2007 at 22:08 UTC

    The reason I suggested Time::Local, though: if your dates are all identicaly shapped and speed is an issue (which it may be at 5 minute intervals) then it's like a million times faster to use timelocal_nocheck. It's more work too, but it can be worth it in some situations.

    Er, I guessed ParseDate was from Date::Manip.

    -Paul

      Yep, that's the ParseDate from Date::Manip. Some work popped up in the middle of posting and I forgot to put everything in there. We run our script a few times a day, but I'm not sure if ParseDate would be fast enough to process data in time for you to do anything useful with it in a 5-minute window. It's just what we use at work because we have to deal with so many date formats in different files. Also because we're about 50% people who like 'MM/DD/YYYY' dates and 50% people who like 'YYYY-MM-DD' dates, and ParseDate was the easiest way to resolve that conflict.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://602611]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-09-23 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls