test.py 631 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3.3
  2. from pyawk import PyAwk, p
  3. class LTSVParser(PyAwk):
  4. def begin(self):
  5. self.FS = '\t'
  6. self.count = 0
  7. def action(self, S):
  8. if not p(S[0], r'status:200'):
  9. self.count += 1
  10. self.print('----------')
  11. d = {}
  12. for elem in S[1:]:
  13. key, value = elem.split(':', 1)
  14. d[key] = value
  15. self.print(d)
  16. def end(self):
  17. self.print('----------')
  18. self.print('Total:{}'.format(self.NR))
  19. self.print('Matched:{}'.format(self.count))
  20. if __name__ == '__main__':
  21. LTSVParser().run()