in reply to Re^12: Log Parsing
in thread Log Parsing

problem with this approach is that $taskid eq $reqid will never be equal

we need something like this which u last time used to get task id

while ( /\{(\d+)-SUCCESSFUL\}/g ){ push @id,$1 if ($taskid eq $reqid); }

and need to iterate around these @id

Replies are listed 'Best First'.
Re^14: Log Parsing
by poj (Abbot) on May 11, 2017 at 13:37 UTC

    Ok try

    #!/usr/bin/perl use strict; my $reqid = '8274'; my $infile = 'worker.log'; open IN,'<',$infile or die "$!"; # input my %data = (); my @id = (); while (<IN>) { chomp; next unless /Task:id=(\d+)/; my $taskid = $1; my (undef,$timestamp,undef) = split /\s+/,$_,3; if (/(Started|Submitted|Done).*(consuming|job)/){ my $i = ($1 eq 'Done') ? 1 : 0; my $proc = ($2 eq 'consuming') ? $2 : 'Submitted'; $data{$taskid}{$proc}[$i] = $timestamp; } while ( /\{(\d+)-SUCCESSFUL\}/g ){ push @id,$1 if ($taskid eq $reqid); } } close IN; # output print join ',',('Task id','Start time',"End time\n"); for my $id (sort @id){ if (exists $data{$id}){ for my $proc (reverse sort keys %{$data{$id}}){ printf "%s,%s,%s\n","$id $proc",@{$data{$id}{$proc}}; } } else { print OUT "$id- no data\n"; } }
    poj

      thanks it is working fine

        one more help is needed the timings which are coming in results contains extra digits something like this 10:04:56.499+0000 but I want only till seconds 10:04:56

        reason being is that I am not able to subtract these timings so I want processing time =endtime-start time for every task id

        Could you please help regarding that, can we subtract them in the same program

      for proper time format I have made changes and it is working fine , I used $timestamp= substr $timestamp, 0, 8;

      but I am not able to find out how to get the subtraction End time and Start time in the same program