Re:Useless Use of Cat Award
by sliverstorm on Wednesday September 11, 2013 @11:13AM
(#6367675)
Pipes also match my thought flow. "wc -l" is a good example.
"Ok, I want to read this file..."
cat file
"Then I want to find foo" cat file | grep foo
"Oh, and I want to know how many lines of foo there are" cat file | grep foo | wc -l
In this trivial example, I could have inserted "-c" with only a few keystrokes, but on a 200 character string of commands it's faster and easier to tack "wc -l" on at the end. Plus I'm not strong enough with grep to do every manipulation I might want, so sometimes that grep will be followed by some perl, or a sort, etc.If you're doing a one-off pipeline on the command line, you can even start with less!
"I want to look through this file..."
less file
"Oh, that's long, I want to look at all the foos..." less file | grep foo
"How many foos are there?" less file | grep foo | wc -l
Try it, it works!This is not some magic behavior of pipelines. Rather, less (like many other terminal programs) is explicitly programmed to behave differently if the output is a terminal. Specifically, the less source code has this comment in it:
"/*
* Output is not a tty.
* Just copy the input file(s) to output.
*/"
grep does this to, which is why the color-coding control characters don't mess up other commands.
FWIW, that's the exact same way I approach that sort of manipulation. Start with the most basic operation, then construct a pipeline going left to right, adding filters / operations as needed to get to the result.
There's value in knowing some of the advanced things that the textutils and bash can do together, and sometimes there's value in using those things. I don't dispute that, but I do dispute the need to shame people who use the tools in ways that you personally don't like.
Shame or not, I'm going to keep using cat at the beginning of my pipelines unless I have a really good reason not to. If that makes some people think I'm not in the Unix wizard in-group, I don't really care.