I have a text file with some lines I'd like to sort. This file is named somefile
.
cat somefile | sort
results in some sorted output being sent to stdout.
cat somefile > anotherfile
results in the output of cat somefile
being written to anotherfile
However
cat somefile | sort > somefile
results in somefile
being empty.
Why is this? I expect somefile
to be sent to stdout, redirected into the sort program which sends sorted output to stdout which is then written to somefile
.