August 23rd, 2005

Splitting log files

You’ve been remiss when it comes to rotating your log files. Now you
want to do some log analysis on your logfiles. What to do.
perl -MIO::All -MDateTime::Format::Strptime -ne '
  my $p = DateTime::Format::Strptime->new(pattern=>"%b-%Y") || die $!;
  my $fname=substr($p->parse_datetime(
                          join("-",
                               (split(m{[:/]}, [split(/\s+/)]->[3]))[1,2]))
                       ->ymd,
                   0, 7);
  io("access-$fname.log")<<$_' access.log


Put all that one one line and you’re good to go.