unix - How to perform sort on all files in a directory? -
how perform sort on files in directory?
i have done in python, seems of hassle.
import os, glob d = '/somedir/' 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
, -exec
:
find /somedir -type f -exec sort -o {} {} \;
for limiting sort
files in directory itself, use -maxdepth
:
find /somedir -maxdepth 1 type f -exec sort -o {} {} \;
Comments
Post a Comment