Categories
Tech

tail and format Apache log files (Perl one-liner)

Here is a quick Perl one-liner that lets you tail an Apache log file and view nicely-formatted output: tail -f YOURDOMAIN_LOG_FILE | perl -ne ‘$|=1;my ($host,$date,$url,$status,$size,$referrer,$agent) = $_ =~ m/^(\S+) – – \[(\S+ [\-|\+]\d{4})\] “(\S+ \S+ [^”]+)” (\d{3}) (\d+|-) “(.*?)” “([^”]+)”$/;print $host . ” – ” . $date . ” – ” . $url .”\n”;’ […]