takes an apache log, and splits it up into a number of logfiles. One for each day traffic took place on. (eventually going to rework it to use date::manip and output the week number as well.
#!/usr/bin/perl -w use strict; ## Just a small file to split apache logs up into days (Should work fo +r any log that has its date and time in the same format as apache [dd +/mm/yy:rest of st amp] ## Nothing particualrly fancy. ## Date extraction from apache log files. combined format. sub get_date_from_log_line{ my %date; my $line = shift; my $dateline=$1 if ($line=~ m/(\[.+?\])/); my @datestring=split(/:/,$dateline); substr($datestring[0],0,1)=""; return $datestring[0]; } ## Basic Variable setups. ## my $pathname=shift(@ARGV) or die("Two arguments please: log file to be + split, and where to put the split files"); my $final_directory=shift(@ARGV) or die("Two arguments please: log fil +e to be split, and where to put the split files"); my $date; my $date_last; my $line; ## /Variables ## open(FILE1,"$pathname") or die("bugger $pathname\n"); $line=<FILE1>; $date=&get_date_from_log_line($line); my $timeStamp=$date; $timeStamp =~ s/\///g; my $outputfile="$final_directory$timeStamp.log"; open (OUTFILE,">$outputfile"); print OUTFILE $line; until (eof(FILE1)) { $line=<FILE1>; $date_last=$date; $date=&get_date_from_log_line($line); if ($date_last ne $date){ close (OUTFILE); $timeStamp=$date; $timeStamp =~ s/\///g; $outputfile="$final_directory$timeStamp.full.log"; open (OUTFILE,">$outputfile") or die("damn it to hell $!\n$outputfile\ +n"); } print OUTFILE $line; } close(OUTFILE); print "Files Split.\n";

Update- revised and removed the .*

In reply to apache log splitter by fuzzysteve

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.