sorting - Using linux sort on multiple files -


is there way can run following command linux many files @ once?

$ sort -nr -k 2 file1 > file2 

i assume have many input files, , want create sorted version of each of them. using like

for f in file*     sort $f > $f.sort done 

now, has small problem if run again, if not sort files again, create file1.sort.sort go file1.sort. there various ways fix that. can fix second problem creating sorted files thate don't have names beginning "file":

for f in file*     sort $f > sorted.$f done 

but that's kind of weird, , wouldn't want files named that. alternatively, use more clever script checks whether file needs sorting, , avoids both problems:

for f in file*     if expr $f : '.*\.sort' > /dev/null             : no need sort     elif test -e $f.sort             : sorted     else         sort -nr -k 2 $f > $f.sort     fi done 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -