Nov 29 2005

Perl bits: Parsing Apache’s Combined log format

Published by Adam at 9:07 pm under ,

A handy dandy regular expression to parse out fields from Apache’s combined log format:

	/^(\S+)\s		# requestor
	(\S+)\s			# ?
	(\S+)\s			# ?
	\[([^\]]*)\]\s		# time
	"([^"]*)"\s		# URL
	(\d*)\s			# result
	(\d*)\s			# bytes
	"([^"]*)"\s		# referrer
    "([^"]*)"$/x    		# user agent

One response so far

One Response to “Perl bits: Parsing Apache’s Combined log format”

  1. Nigel Peckon 30 Jan 2010 at 11:48 am

    Thanks for this, very useful. I updated the code to fill in your question makrs:

    /^
    (\S+)\s # requestor
    (\S+)\s # RFC 1413 identity of the client determined by identd (highly unreliable – do not use)
    (\S+)\s # http userid
    \[([^\]]*)\]\s # time
    “([^"]*)”\s # URL
    (\d*)\s # result
    (\d*)\s # bytes
    “([^"]*)”\s # referrer
    “([^"]*)” # user agent
    $/x;

Comments RSS

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes