Created
January 24, 2014 00:25
-
-
Save roberto/8589698 to your computer and use it in GitHub Desktop.
parsing log file (method, path, protocol and status code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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