Results 1 to 3 of 3
his,
this is some quirk or something.
i have this line in a bash script:
Code:
cat $sortfile | sort -nr > $sortfile
$sortfile is some text file with lines ...
- 11-17-2009 #1
[SOLVED] sometimes works, sometimes doesn't !?
his,
this is some quirk or something.
i have this line in a bash script:
$sortfile is some text file with lines like:number.some_text ...Code:cat $sortfile | sort -nr > $sortfile
i don't understand why this works erratically...
i changed to:
and now it seems okCode:cat $sortfile | sort -nr > $sortfile-2
what should i be learning here?...
- 11-18-2009 #2
That you mess up the file by writing to it while reading from it this way.
Sort doesn't write to the new file before it received EOF from the input. So that's not the problem. But nevertheless the file is created by the shellt right when the command starts.
Try it out. Open two terminals and take a random text file "test.txt" with some content in it. Now type "cat | sort -n > test.txt" in the second terminal. The command waits for input from the keyboard until you press CTRL+D.
But the file "test.txt" is erased already so as to make it ready to receive the data yet to come, as you can check on terminal 1. So sort would get input from a file already empty.
"sort -onr $file $file" should do the job.Debian GNU/Linux -- You know you want it.
- 11-18-2009 #3
Thanks GNU-Fan!
now its clearer.



