To sort all the results chronologically means that I would have to read them all in first (they could get quite large), perform the sort, and print out the output. I thought of the following alternative options:

Assuming each log file is in chronological order wouldn't it be easier to go through them in parallel, writing out the the entries in order as you go? Something like this:

# MAKE A FILEHANDLE FOR EACH FILE WE WERE GIVEN my @files = map {new IO::File $_ or die "could not open $_\n"} @ARGV; # READ IN A LINE FOR EACH FILE my @lines = map {scalar(<$_>)} @files; # GET THE DATES FOR EACH LINE; my @dates = map {get_time($_)} @lines; my $MAX = <some date bigger than anything in the logs>; my $found; do { # FIND THE LINE WITH THE EARLIEST DATE my $min = $MAX; $found = undef; for (my $i=0; $i<$num_logs; $i++) { my $num = $dates[$i]; if ($num < $min) { $found = $i; $min = $num; }; }; if (defined($found)) { # IF WE FOUND A LINE, SHOW IT AND READ THE NEXT # LINE IN FOR THAT LOG FILE print $lines[$found]; my $io = $files[$found]; $lines[$found] = <$io>; $dates[$found] = get_time($lines[$found]); }; } while (defined($found));

I did something similar to this to merge multiple apache access logs together a few years back.


In reply to Re: Log parsing by timestamp dilema by adrianh
in thread Log parsing by timestamp dilema by Limbic~Region

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.