Created
April 23, 2011 20:41
-
-
Save sc68cal/938960 to your computer and use it in GitHub Desktop.
MapReduce example
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
#!/usr/bin/env python | |
import sys | |
import re | |
prog = re.compile("From.*\S{3}\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{2}:\d{2}:\d{2}\s\d{4}") | |
for line in sys.stdin: | |
res = prog.search(line.strip()) | |
if res: | |
res = res.group().split(" ") | |
print '%s %s %s %s\t%s' % (res[2],res[3],res[4],res[6],1) | |
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
#!/usr/bin/env python | |
import sys | |
results = {} | |
for line in sys.stdin: | |
line = line.strip() | |
date,count = line.split("\t",1) | |
try: | |
count = int(count) | |
except: | |
pass | |
results[date] = results.get(date,0) + count | |
for date,count in results.iteritems(): | |
print '%s\t%s' % (date,count) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment