++ to what MidLifeXis said. As logs tend to be sorted already, it's likely you can avoid the sort as the only part that's likely to be a problem memory-wise.

To add to that, for data this size it may be worth running a little preprocessor in C, especially if your log format has fixed-size fields or other delimiters easily recognized with C string functions. That way you could both split the parsing over two CPU cores and avoid running slow regexen (or even substr() which is fast for Perl but still doesn't even come close to C). Something like this (largely untested but you get the idea):

#include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> int main(int argc, char *argv[]) { char buf[10000]; FILE *fh; if(2 != argc) { fputs("Usage: filter <log>\n", stderr); exit(1); } if(!(fh = fopen(argv[1], "r"))) { perror("Cannot open log"); exit(1); } while(!fgets(buf, sizeof(buf), fh)) { static const size_t START_OFFSET = 50; size_t len = strlen(buf); char *endp; if('\n' != buf[len-1]) { fputs("WARNING: line did not fit in buffer, skipped\n", stder +r); continue; } endp = buf + START_OFFSET; len = 20; // To search for a blank after the field instead of using a fixe +d width // endp = strchr(buf + START_OFFSET, ' '); // len = endp ? endp - (buf + START_OFFSET) : len - START_OFFSE +T; // careful with strchr()==NULL fwrite(buf + START_OFFSET, 1, len, stdout); } }

Edit: jhourcle's post just reminded me of the part I missed initially, namely that it's an Apache log. So if you use the standard combined format you could just use START_OFFSET=9 and len=11 to print only the date, if you don't want to differentiate by result code. Then a simple

my %h; $h{$_}++ while(<>);
would get the requests-per-date counts and the only slightly trickier thing is to get them sorted chronologically on output. Something like
for(sort { $a->[0] <=> $b->[0] } map { [ Date::Parse::str2date($_) => +chomp ] } keys %h) { print "$_->[1]: $h{"$_\n"}\n; }

In reply to Re: Working with a very large log file (parsing data out) by mbethke
in thread Working with a very large log file (parsing data out) by calebcall

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.