3 ms·
Sort to the same output file: sort -o foo.txt foo.txt You can't do sort foo > foo because you'll be left with a blank file.
by caw 15y ago
Sort to the same output file:
sort -o foo.txt foo.txt
You can't do sort foo > foo because you'll be left with a blank file.
- Karellen 15y agosponge(1) from "moreutils" Although sort(1) handles this for you as you mention, the general problem in the shell of wanting to overwrite your input file with the output file, but not being able to redirect to it for the reason you mention, is solved with sponge. Rather than: $ grep "foo" bar.txt >baz.txt; mv baz.txt bar.txt instead: $ grep "foo" bar.txt | sponge bar.txt