Skip to content

Instantly share code, notes, and snippets.

@baniol
Created October 13, 2014 11:57
Show Gist options
  • Save baniol/4237c7da23026873da34 to your computer and use it in GitHub Desktop.
Save baniol/4237c7da23026873da34 to your computer and use it in GitHub Desktop.
Filter logs files for regexp & uniq
import re
# open('not_found.log','w').writelines([ line for line in open('allLogs.log') if 'not found' in line])
fname = 'allLogs.log'
with open(fname) as f:
content = f.readlines()
new = [line for line in content if 'not found' in line]
filtered = []
for line in new:
line = re.sub(r'^.*WSLog - ', '', line)
filtered.append(line)
# print(filtered)
open('not_found.log','w').writelines(set(filtered))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment