Why there is no use of cat when piping with sort?

It was explained that when we pipe and cat with wc it will look like that:
cat XXXX.txt | wc | cat > YYYY.txt
and that because that the second cat receive the cat XXX | wc as input (and redirect to YYYY).

So why we don’t do the same with sort?
in sort it shows: cat XXXX.txt | sort > YYYY.txt
why not putting another | cat?


Thanks for the helpers (:

Those commands should be written as:

wc XXXX.txt > YYYY.txt
sort XXXX.txt > YYYY.txt

Or if those programs weren’t able to read from files directly:

wc < XXXX.txt > YYYY.txt
sort < XXXX.txt > YYYY.txt

You can chain cat indefinitely since all it does is repeat the same data, it’s often redundant.

When I use cat it’s to display a small file (cause cat will write the file to stdout which is going to show up in the terminal) - or to do the opposite, use cat to read from stdin (the terminal) and redirect to some file (allowing me to paste into a file)

Keep in mind that its namesake is concatenate, this repeating behaviour is just what you get when you concatenate a single file and is seldom needed for using other programs. Redundant use of cat is a pretty common mistake.


Thank you very much Ionatan! :grin:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.