Skip to content

Instantly share code, notes, and snippets.

@t0mmyt
Last active December 26, 2015 12:59
Show Gist options
  • Save t0mmyt/7154865 to your computer and use it in GitHub Desktop.
Save t0mmyt/7154865 to your computer and use it in GitHub Desktop.
Populate dict from bzipped log file
def populate(file, result):
'''
Read bzipped syslog and match re below, append to dict referred to
by result.
Requires re and bz2
'''
f = BZ2File(file, 'r')
re_aide = re.compile('^\w+ \d+ \d\d:\d\d:\d\d ([\w\-\.]+) aide: (.*)$')
while 1:
lines = f.readlines(8192)
if not lines:
break
for line in lines:
m = re_aide.match(line)
if m:
s, d = m.group(1), m.group(2)
if s not in result or not isinstance(result[s], list):
result[m.group(1)] = []
result[s].append(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment