When I pipe multiple unix commands such as grep, sed, tr etc. I tend to specify the input file that is being processed using cat. So something like
cat file | grep ... | awk ... | sed ... .
But recently after a couple of comments left on my answers indicating that this was a useless use of cat, I thought I would ask the question here.
The closest question I came across here was this one: Is it wasteful to call cat? – but it's not quite what I'm asking.
I guess what the UUOC camp suggest is to use
cmd1 args < file | cmd2 args | cmd3 .. or if the command has an option to read from file then to pass in the file as an argument.
But to me
cat file | cmd1 ... | cmd2 seems much easier to read and understand. I don't have to remember different ways of sending input files to different commands, and the process flows logically from left to right. First input, then the first process … and so on.
Am I failing to understand what arguments are being made about the useless use of cat? I understand that if I'm running a cron job that runs every 2 seconds that does a lot of processing, then in that case cat might be wasteful. But otherwise what's the general consensus on the use of cat?