i'm having iis server log file, know has field called cs(referer).i want values under column?please me?
#!/usr/bin/env python f = open('log.txt','r') data = f.read() import re #print data def find(pat,text): match = re.search(pat,text) if match: print match.group() else: print 'not found!'
the logic follows:
- find "#fields:" comment , find out index of columns
- skip comment lines begin "#"
- print column we're interested in
code:
#!/usr/bin/env python f = open('log.txt','r') columns = {} line in f.readlines(): if line.startswith('#fields:'): index, substring in enumerate(line.split(' ')): columns[substring] = index elif line.startswith('#'): continue else: print line.split(' ')[columns['cs(user-agent)']]
Comments
Post a Comment