DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Apache Access Log Parser

  • submit to reddit
        // This is a perl script that will open an Apache  access log file and parse it for daily and hourly hits.

#!/usr/bin/perl -w

open(DAT, "$data_file") || die("Could not open file!");


foreach $line(@raw_data)
      if (($line !~ $appcheckfilter) && ($line !~ $localhostfilter))  {
        ($a1,$filter) = split(/]/,$line);
        ($filter,$b1) = split(/\[/,$a1);
        ($datetimefilter,$filter) = split(/\ -/,$b1);
        ($datelog,$hourlog,$minutelog,$secondlog) = split(/:/,$datetimefilter);
        if ($hourlog eq $prevhourlog) {
        } else {
           print "$datelog, $prevhourlog: $counter\n";
        $prevhourlog = $hourlog;
print "$datelog: $counter\n";