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

thanks it is working but its providing details for all task id but I need it for particular task ids ( of a parent id)

I tried to make changes but still its showing data for all task id

#!/usr/bin/perl use strict; my $infile = 'worker.log'; my $outfile = 'Consumer.CSV'; my @id = (); print "Please enter the parentid of running process: \n" ; my $reqid = <STDIN>; chop $reqid; open IN,'<',$infile or die "$!"; # input my %data = (); 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 open OUT,'>',$outfile or die "$!"; my @cols = qw(Taskid Started Done); printf OUT "%s,%s,%s\n",@cols; #print join ',',('Task id','Start time',"End time\n"); for my $id (reverse sort keys %data){ printf OUT "%s,%s,%s\n",$id,@{$data{$id}}; }

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

    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

      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