python - get all values in cs(Referer) -


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:

  1. find "#fields:" comment , find out index of columns
  2. skip comment lines begin "#"
  3. 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