Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to generate a second file to sort a file?

I want to sort a bunch of files. I can do

sort file.txt > foo.txt
mv foo.txt file.txt

but do I need this second file?

(I tried sort file.txt > file.txt of course, but then I just ended up with an empty file.)

like image 368
Nagel Avatar asked Feb 02 '12 17:02

Nagel


1 Answers

Try:

sort -o file.txt file.txt

See http://ss64.com/bash/sort.html

`-o OUTPUT-FILE'
     Write output to OUTPUT-FILE instead of standard output.  If
     OUTPUT-FILE is one of the input files, `sort' copies it to a
     temporary file before sorting and writing the output to
     OUTPUT-FILE.
like image 198
Andrew Cooper Avatar answered Oct 12 '22 23:10

Andrew Cooper