Skip to content

Instantly share code, notes, and snippets.

@jasonhancock
Last active December 11, 2015 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonhancock/4675588 to your computer and use it in GitHub Desktop.
Save jasonhancock/4675588 to your computer and use it in GitHub Desktop.
stupid quick and dirty script to parse apache combined log format
#!/usr/bin/perl
use strict;
use warnings;
my $file = $ARGV[0] or die("No file passed");
open IN, "<$file" or die("Can't open file $file");
while(my $line=<IN>) {
if($line=~m/^(\S+|::1) \S+ \S+ \[([^\]]+)\] "([A-Z]+)[^"]*" \d+ (\d+|-) "[^"]*" "([^"]*)"$/m) {
my $user_ip = $1;
my $ts = $2;
my $method = $3;
my $bytes = $4;
my $ua = $5;
#print "$1 $2 $3 $4 $5\n";
#print "it matched $line\n";
} else {
print "line didn't match $line\n";
}
}
close IN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment