2 ms·
Not well tested... just whipped this up. The example to sort df -h by the percent: df -h | p 'sorted({}[1:], key=lambda x: int(x.split()[-2][:-1]))' I save
by ericfrederich 8y ago
Not well tested... just whipped this up.
The example to sort df -h by the percent:
df -h | p 'sorted({}[1:], key=lambda x: int(x.split()[-2][:-1]))'
I saved this as ~/bin/p
#!/usr/bin/env python3
import sys
single_line = sys.argv[1] == '-l'
code = ' '.join(sys.argv[2 if single_line else 1:])
if single_line:
for line in sys.stdin:
print(eval(code.format('line.strip()')))
else:
print('\n'.join(eval(code.format('sys.stdin.read().splitlines()'))))