Posted By

brm on 12/15/15


Tagged

regex parser


Versions (?)

Parser log


 / Published in: Python
 

Parsing log from url & filter pattern match using regex

  1. #!/usr/bin/python
  2.  
  3. import urllib2, re
  4.  
  5. pattern = re.compile('(id=\S*@\S*)\W(T=".*)')
  6. data = urllib2.urlopen("http://c.hlp.sc/ZKtU/download/test-sample.log")
  7. for line in data:
  8. for match in pattern.findall(line):
  9. print match[0].replace('\n', ' '),
  10. print match[1].replace('\n',' ')

Report this snippet  

You need to login to post a comment.