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

Just skip over the other ids

# chop $reqid; # use chomp chomp $reqid;
see chomp
while (<IN>) { chomp; next unless /Task:id=(\d+)/; my $taskid = $1; next unless ($taskid eq $reqid); ## <-- add my (undef,$timestamp,undef) = split /\s+/,$_,3; ..
poj

Replies are listed 'Best First'.
Re^13: Log Parsing
by piyushmnnit06 (Novice) on May 11, 2017 at 12:49 UTC

    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

      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

        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