baniol
10/13/2014 - 11:57 AM

Filter logs files for regexp & uniq

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))