This produces the required output but I'm not convinced that it does what is required.
Output#!/net/perl/5.10.0/bin/perl use strict; use warnings; use 5.010_000; use DateTime::Format::Strptime; use Readonly; Readonly my $delta => 60 * 60; my %stats; my $log_parser = qr{ \A (?<time_stamp> \d{4}-\p{IsAlpha}{3}-\d\d [ ] \d\d:\d\d:\d\d ) .* [ ] - [ ] id [ ] = [ ] (?<id> \d+ ), [ ] Status [ ] = [ ] (?<status> \w+ ) }msx; my $date_parser = new DateTime::Format::Strptime( pattern => '%Y-%b-%d %T', on_error => 'croak', ) or die "Can't create date parser: $!\n"; while ( my $line = <DATA> ) { if ( $line =~ /$log_parser/ ) { my ( $time_stamp, $id, $status ) = @+{qw(time_stamp id status) +}; next if $status eq 'success'; my $date = $date_parser->parse_datetime($time_stamp); || $stats{$id}[-1][0]->subtract_datetime_absolute($date)-> +seconds > $delta ) { push @{ $stats{$id} }, [ $date, $time_stamp, 0 ]; } else { ++$stats{$id}[-1][2]; } } } if ( scalar keys %stats ) { say 'ID last attempted attempts'; say '=' x 44; foreach my $id ( sort keys %stats ) { foreach my $time ( @{ $stats{$id} } ) { printf "%s %s %8d\n", $id, @{$time}[ 1, 2 ]; } } } __DATA__ 2008-Feb-01 00:00:02 UTC (GMT +0000) - id = 000000001, Status = failed 2008-Feb-01 00:10:02 UTC (GMT +0000) - id = 000000002, Status = succes +s 2008-Feb-01 00:20:02 UTC (GMT +0000) - id = 000000003, Status = failed 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 2008-Feb-01 01:00:02 UTC (GMT +0000) - id = 000000001, Status = failed 2008-Feb-01 01:10:02 UTC (GMT +0000) - id = 000000007, Status = succes +s 2008-Feb-01 01:20:02 UTC (GMT +0000) - id = 000000003, Status = failed 2008-Feb-01 01:30:02 UTC (GMT +0000) - id = 000000009, Status = succes +s
ID last attempted attempts ============================================ 000000001 2008-Feb-01 00:00:02 1 000000003 2008-Feb-01 00:20:02 1
In reply to Re: Logfile analysis : How to differentiate records with timestamp
by hipowls
in thread Logfile analysis : How to differentiate records with timestamp
by tuakilan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |