Skip to content

Instantly share code, notes, and snippets.

@upvalue
Created August 2, 2012 17:55
Show Gist options
  • Save upvalue/3239136 to your computer and use it in GitHub Desktop.
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)
#!/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]))
@upvalue
Copy link
Author

upvalue commented Aug 17, 2012

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])))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment