xonsh/tests/bin/wc

16 lines
309 B
Text
Raw Normal View History

#!/usr/bin/env python3
2016-10-25 20:41:20 -04:00
import sys
if len(sys.argv) == 1:
f = sys.stdin.buffer
doc = f.read()
2016-10-25 20:41:20 -04:00
else:
with open(sys.argv[1], 'rb') as f:
doc = f.read()
2016-10-25 20:41:20 -04:00
lines = len(doc.splitlines())
words = len(doc.split())
bytes = len(doc)
print(' {0} {1:>2} {2} {3}'.format(lines, words, bytes, f.name))