Madhavan11 has asked for the wisdom of the Perl Monks concerning the following question:

The file is structured like this:
<28 Jan 2014 00:08:24> 00001 startmessage1 <28 Jan 2014 00:08:24>00001 msg1 <28 Jan 2014 00:08:24>00001 msg1 <28 Jan 2014 00:08:24>00001 startmessage2 <28 Jan 2014 00:08:25>00001 msg2 <28 Jan 2014 00:08:25>00001 msg2 <28 Jan 2014 00:08:25>00001 msg2 <28 Jan 2014 00:08:25>00001 msg2 <28 Jan 2014 00:08:25>00001 msg2 <28 Jan 2014 00:08:26>00001 msg2 <28 Jan 2014 00:08:26>00001 Endmessage2 <28 Jan 2014 00:08:26>00001 msg1 <28 Jan 2014 00:08:26>00001 msg1 <28 Jan 2014 00:08:27>00001 startmessage3 <28 Jan 2014 00:08:27>00001 msg3 <28 Jan 2014 00:08:28>00001 msg1 <28 Jan 2014 00:08:28>00001 msg1 <28 Jan 2014 00:08:30>00001 Endmessage1 <28 Jan 2014 00:08:31>00001 msg3 <28 Jan 2014 00:08:31>00001 msg3 <28 Jan 2014 00:08:31>00001 msg3 <28 Jan 2014 00:08:31>00001 Endmessage3
Date and time, ID, log message... have to find the start message and corresponding end message to culculate the timing. output should be
28 Jan 2014 00:08:24 |startmessage1 |Endmessage1 |00001| 6 seconds 28 Jan 2014 00:08:24 |startmessage2 |Endmessage2 |00001| 2 seconds
print 'THREAD ID,LOG DETAILS'."\n"; foreach my $filename (glob("$dir/*.out")) { open(my $fh, "<", $filename) or die "Could not open '$filena +me'\n"; while ($line = <$fh>) { my $i=2; chomp($line); if($line=~ $startmsg[$i]) { chomp ($line); my $threadid=$line; $threadid =~ s!(\d*)\s*.*!$1!; my $startdetails=$line; $startdetails =~ s!(\d*)\s*(.*)!$2!; chomp($threadid); print "$threadid,$startdetails \n"; my $flag = 'False'; OUTER: while ($line = <$fh>) { if ($line=~ m/$threadid/) if($line=~ $endmsg[$i]) { chomp ($line); my $enddetails=$line; $enddetails =~ s!(\d*) +\s*(.*)!$2!; print "$threadid,$endd +etails\n"; $flag='True'; last OUTER; } } } } } close($fh); }
Please help me

Replies are listed 'Best First'.
Re: How to find the Start and end line from the file ?
by pajout (Curate) on Feb 03, 2014 at 12:48 UTC
    Please, format your question properly and show us your code...
Re: How to find the Start and end line from the file ?
by Kenosis (Priest) on Feb 03, 2014 at 18:11 UTC