Fortran,
I would do it a little differently, I would not sort the file into itself. Just incase anything new gets added to the files after the sort. here is what I would do:
- mirrior the dir tree that has a 'output.txt' file and put the sorted file there
like so:
#!/bin/bash
LIST=`find $1 -name output.txt`
for i in $LIST ; do
X=`dirname $i`
mkdir -p "sorted/$X"
sort "$i" -o "sorted/$i"
done
the above needs a bit of polish, mkdir should have an 'if' around it and $1 should be checked for sanity
gives you this:
orignal:
mytest
mytest/ccc
mytest/ccc/f
mytest/ccc/f/output.txt
mytest/ccc/d
mytest/ccc/d/output.txt
mytest/ccc/e
mytest/ccc/e/output.txt
mytest/bbb
mytest/bbb/f
mytest/bbb/d
mytest/bbb/e
mytest/aaa
mytest/aaa/f
mytest/aaa/f/output.txt
mytest/aaa/d
mytest/aaa/d/output.txt
mytest/aaa/e
mytest/aaa/e/output.txt
Output:
sorted
sorted/mytest
sorted/mytest/ccc
sorted/mytest/ccc/f
sorted/mytest/ccc/f/output.txt
sorted/mytest/ccc/d
sorted/mytest/ccc/d/output.txt
sorted/mytest/ccc/e
sorted/mytest/ccc/e/output.txt
sorted/mytest/aaa
sorted/mytest/aaa/f
sorted/mytest/aaa/f/output.txt
sorted/mytest/aaa/d
sorted/mytest/aaa/d/output.txt
sorted/mytest/aaa/e
sorted/mytest/aaa/e/output.txt
one last thing I think the sort output file is writen to a tmp file and then renamed when the sort is done, otherwise the output file could truncate the input file before everything was read. Like sed's inplace option.