Piping cat into a command like wc is easier and more organic to come up with, and easier for other people to read when they come across it.
Unless you're putting this in a function that's going to be called. thousands of times, you don't gain any humanly useful efficiency by using a standard input redirect instead.
The notion that piping cat is "useless" is itself a useless conception, and is basically bad in the ways premature optimization is bad. Go away.
I don't think I've seen the <file command syntax used anywhere in a long time. It's fairly unknown
The reason for using cat to wc, or grep to wc (instead of grep -c) is that you usually start out with what's on the LHS, verifying its output when run standalone, and then appending the pipe and what's on the RHS. This is a clean left-to-right thought process; quicker and more intuitive and maintainable than tweaking the command you started with on the LHS of the pipe to add a -c flag or remove the cat or whatever
Agreed, I prefer to use cat in this way even though I know it's unneccesary. I like commands to have a consistent flow from left to right. It looks nicer and, to me, makes it slightly more readable.
I actually wrote that in my original comment, but decided to test just before submitting and I realised you can also do that with redirection as long as you put the redirect at the start of the command.
anon@anon-pc:/tmp$ cat test #my example file
3
2
1
anon@anon-pc:/tmp$ cat test | sort #the original command, before adding an additional step to the pipe
1
2
3
anon@anon-pc:/tmp$ cat test | grep -v 2 | sort #adding an extra step
1
3
anon@anon-pc:/tmp$ <test sort #original command, but without cat
1
2
3
anon@anon-pc:/tmp$ <test grep -v 2 | sort #still allows you to add the extra step easily
1
3
View all comments
Show parent comment
-7
u/Downvote_machine_AMA Jan 13 '17
Piping cat into a command like wc is easier and more organic to come up with, and easier for other people to read when they come across it.
Unless you're putting this in a function that's going to be called. thousands of times, you don't gain any humanly useful efficiency by using a standard input redirect instead.
The notion that piping cat is "useless" is itself a useless conception, and is basically bad in the ways premature optimization is bad. Go away.