Hi,

I need your help to find a fast algorithm to process log files, finding the pairs and then generate a new logfile joining the pairs information in a single entry.

I have to process log files that are generated per minute, so my processing time should be below a minute.

An example of the logfiles:

FILE_MINUTE_0.log
20090619 ID = 0 TIMESTAMP = 1244127600 COUNT_2 = 10
FILE_MINUTE_1.log
20090619 ID = 0 TIMESTAMP = 1244127600 COUNT_1 = 10 20090619 ID = 1 TIMESTAMP = 1244127600 COUNT_1 = 10 20090619 ID = 1 TIMESTAMP = 1244127600 COUNT_2 = 10 20090619 ID = 2 TIMESTAMP = 1244127600 COUNT_1 = 10 20090619 ID = 3 TIMESTAMP = 1244127600 COUNT_2 = 10 20090619 ID = 4 TIMESTAMP = 1244127600 COUNT_1 = 10
FILE_MINUTE_2.log
20090619 ID = 4 TIMESTAMP = 1244127600 COUNT_2 = 10

I've to process the above files and generate a new one joining the entries with the same ID. This would be the final Log File after processing "FILE_MINUTE_1.log"

FINAL_FILE_1.log
20090619 ID = 0 TIMESTAMP = 1244127600 TOTAL = COUNT_1 + COUNT_2 20090619 ID = 1 TIMESTAMP = 1244127600 TOTAL = COUNT_1 + COUNT_2 20090619 ID = 2 TIMESTAMP = 1244127600 TOTAL = COUNT_1 --> COUNT_2 does Not exist 20090619 ID = 4 TIMESTAMP = 1244127600 TOTAL = COUNT_1 + COUNT_2

From the above file the record with ID=3 doesn't appear since its a pair without the entry "COUNT_1"

My approaches:

1. Put the log entries into a temporary SQL table, and then generate the output based on a Query that joins the entries by ID.

2. Put All the log entries into HASH TABLE like this:

$hash = ( 'FILE_MINUTE_2' => { 1 => {ID=1, COUNT_1 = 10, COUNT_2 = 20}, 2 => {ID=2, COUNT_1 = 10, COUNT_2 = undef}, 3 => {ID=3, COUNT_1 = undef, COUNT_2 = 20}, 4 => {ID=4, COUNT_1 = 10, COUNT_2 = 20}, }, );

And after reading the LogFiles, then I just need to process the HASH TABLE in order to generate the output file.

Another considerations:

Any tip will be helpful. Tks


In reply to Process Log Files - Join Log entry pairs by gulden

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.