]> code.delx.au - monosys/blob - scripts/count.py
Added line count script
[monosys] / scripts / count.py
1 #!/usr/bin/env python
2 # Print a line count. Given an input file like this:
3 # apple
4 # apple
5 # banana
6 # carrot
7 # apple
8 #
9 # Your output will be
10 # apple 2
11 # banana 1
12 # carrot 1
13 # apple 1
14
15 import sys
16
17 last = ""
18 count = 0
19 for line in sys.stdin:
20 line = line.strip()
21 if line == last:
22 count += 1
23 else:
24 if last:
25 print last, count
26 last = line
27 count = 1
28
29 print last, count
30