tuakilan has asked for the wisdom of the Perl Monks concerning the following question:
Herewith are the log file which was generated by a close source C program which was beyond my knowledge
ReadLog.txt
<b>2008-Feb-01 00:00:02 UTC (GMT +0000) - id = 000000001, Status = fai +led</b> 2008-Feb-01 00:10:02 UTC (GMT +0000) - id = 000000002, Status = succes +s <b>2008-Feb-01 00:20:02 UTC (GMT +0000) - id = 000000003, Status = fai +led</b> 2008-Feb-01 00:30:02 UTC (GMT +0000) - id = 000000004, Status = succes +s 2008-Feb-01 00:40:02 UTC (GMT +0000) - id = 000000001, Status = succes +s 2008-Feb-01 00:50:02 UTC (GMT +0000) - id = 000000001, Status = succes +s <b>2008-Feb-01 01:00:02 UTC (GMT +0000) - id = 000000001, Status = fai +led</b> 2008-Feb-01 01:10:02 UTC (GMT +0000) - id = 000000007, Status = succes +s <b>2008-Feb-01 01:20:02 UTC (GMT +0000) - id = 000000003, Status = fai +led</b> 2008-Feb-01 01:30:02 UTC (GMT +0000) - id = 000000009, Status = succes +s
ResultLog.txt
ID last attempted attempts ============================================================ 000000001 2008-Feb-01 01:00:02 1 000000003 2008-Feb-01 01:20:02 1
I tried the following but the output wasn't desirable.
use strict; use warnings; use DateTime::Format::Strptime; # my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d % +T',); my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d %T' +, on_error => 'croak'); my $infile = 'ReadLog.txt'; my $outfile = 'ReportLog.txt'; my($fh_out, $fh); my %lookup; my $status = 'failed'; my $time_delta = 3600; # seconds = 1 hour open($fh_out, '>', $outfile) or die "Could not open outfile: $!"; open($fh, '<', $infile) or die "Could not open logfile: $!"; while (<$fh>) { next unless /$status/; $_ =~ m/^(.*) UTC.*refs = (\d+)$/; # my $dt = $Strp->parse_datetime("$1"); unless (my $dt = $Strp->parse_datetime($1)) { warn "invalid datetime: $1"; next; } my $timestamp = $dt ->epoch(); my $refs = "$2"; if ( defined($lookup{$refs}) && $lookup{$refs} + $time_delta <= $t +imestamp ) { print $fh_out "REFS $refs: occurrences at " . $lookup{$refs} . + "and $timestamp \n"; print "REFS $refs: occurrences at " . $lookup{$refs} . " and $ +timestamp \n"; } $lookup{$refs} = $timestamp; } close $fh_out; #close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Logfile analysis : How to differentiate records with timestamp
by moritz (Cardinal) on Mar 11, 2008 at 08:09 UTC | |
|
Re: Logfile analysis : How to differentiate records with timestamp
by hipowls (Curate) on Mar 11, 2008 at 10:01 UTC | |
by tuakilan (Acolyte) on Mar 11, 2008 at 13:27 UTC | |
by hipowls (Curate) on Mar 11, 2008 at 20:17 UTC | |
by tuakilan (Acolyte) on Mar 12, 2008 at 00:12 UTC |