Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created June 11, 2012 17:03
Show Gist options
  • Save hanigamal/2911312 to your computer and use it in GitHub Desktop.
Save hanigamal/2911312 to your computer and use it in GitHub Desktop.
Parse S3 log files using Perl regular expressions
#!/usr/bin/perl -w
use strict;
while (my $line=<>) {
my ($date, $host, $url_with_method, $status, $size, $referrer, $agent) = $line =~
m/^\S+\s+\S+\s+\[(\S+\s+[\-|\+]\d{4})\]\s+(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+"(\S+\s+\S+\s+[^"]+)"\s+(\d{3})\s+\S+\s+(\d+|-)\s+\d+\s+\d+\s+\d+\s+"(.*?)"\s+"(.*?)"/;
# Print relevant bits
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment