How do I perform sort on all files in the directory?
I could have done it in python, but it seems to be too much of a hassle.
import os, glob
d = '/somedir/'
for f in glob.glob(d+"*"):
f2 = f+".tmp"
# unix~$ cat f | sort > f2; mv f2 f
os.system("cat "+f+" | sort > "+f2+"; mv "+f2+" "+f)
Use find
and -exec
:
find /somedir -type f -exec sort -o {} {} \;
For limiting the sort
to the files in the directory itself, use -maxdepth
:
find /somedir -maxdepth 1 -type f -exec sort -o {} {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With