Skip to content

Instantly share code, notes, and snippets.

@roberto
Created January 24, 2014 00:25
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 roberto/8589698 to your computer and use it in GitHub Desktop.
Save roberto/8589698 to your computer and use it in GitHub Desktop.
parsing log file (method, path, protocol and status code)
import re
import sys
#example 10.223.157.186 - - [15/Jul/2009:15:50:35 -0700] "GET /assets/js/lowpro.js HTTP/1.1" 200 10469
pattern = re.compile(r'"(?P<method>.+)\s+(?P<path>.+)\s+(?P<protocol>.+)"\s+(?P<status>\S+)')
for line in sys.stdin:
matches = pattern.match(line)
result = matches.groupdict()
print "{0}\t{1}".format(result["path"], result["status"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment