This isn't a bug in sort. The ">" redirection operator in your shell opens
and truncates the file to ready it for output before your shell invokes
sort. After sort starts running and opens and reads the foo.txt file, it
finds that empty file and outputs nothing, as you would expect if you had
purposely given an empty file to sort.

You'll need to use a temporary file in order to avoid this.

sort foo.txt > foo.txt.tmp ; mv foo.txt.tmp foo.txt

On Tue, Mar 28, 2017 at 7:13 AM, Ismael Cama <[email protected]>
wrote:

> When you try to sort a file and write the result in the same file, all the
> contents are deleted. Example:
>
> sort foo.txt > foo.txt
>

Reply via email to