Created
August 2, 2012 17:55
-
-
Save upvalue/3239136 to your computer and use it in GitHub Desktop.
get and sort the line count of each file (so you can find the largest ones)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# usage: ./largest-files.py <file> ... | |
# for instance: ./largest-files.py *.c | |
# to find the largest c file in the current directory | |
import glob, sys, os, pprint | |
files = sys.argv[1:] | |
lines = [] | |
for x in files: | |
output = os.popen('wc -l %s' % (x)).read() | |
lines.append((x,int(output.split(' ')[0]))) | |
pprint.pprint(sorted(lines, key = lambda lns: lns[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import sys, os, pprint; pprint.pprint(sorted([os.popen('wc -l %s' % (x)).read().strip() for x in sys.argv[1:]], key = lambda ln: int(ln.split(' ')[0])))