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

In reply to How to find the Start and end line from the file ? by Madhavan11

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.