foreach $line () { chomp($line); foreach $childid (@Task_id) { #### #!/usr/bin/perl use strict; my %data = (); my @id = (); my $reqid = '8274'; my $infile = 'worker.log'; my $outfile = 'data.CSV'; open IN,'<',$infile or die "$!"; # input while () { chomp; next unless /Task:id=(\d+)/; my $taskid = $1; my (undef,$timestamp,undef) = split /\s+/,$_,3; if (/(Started|Done).+topic (\d+_(\d+)_.+)/){ $data{$3}{$1} = $timestamp; $data{$3}{'Topic'} = $2; } while ( /\{(\d+)-SUCCESSFUL\}/g ){ push @id,$1 if ($taskid eq $reqid); } } close IN; # output open OUT,'>',$outfile or die "$!"; my @cols = qw(Topic Started Done); printf OUT "%s,%s,%s\n",@cols; for my $id (sort @id){ if (exists $data{$id}){ printf OUT "%s,%s,%s\n", map { $data{$id}{$_} } @cols; } else { print OUT "$id - no data\n"; } } close OUT;