3 ms·
hah, I knew someone would point that out (which is why I talked about it in the article). I actually prefer useless cat because when you're prototyping a pipel
by robertelder 7y ago
hah, I knew someone would point that out (which is why I talked about it in the article).
I actually prefer useless cat because when you're prototyping a pipeline it's very awkward to use non-useless cat. You'll probably start off with something like this to observe the content of the file:
cat something.txt
Using this doesn't work in bash:
<something.txt
Then, continuing with useless cat to build on it you do
cat something.txt | grep stuff
Which you can type easily from using 'up' in your terminal. But if you use non-useless cat you have to re-type the entire thing or move the cursor around:
grep stuff < something.txt
With useless cat, you can keep adding things and check the result:
cat something.txt | grep stuff | sed 's/"//g'
Or if you need to insert another filter before the last stage like this, you can just press "up" and insert it:
cat something.txt | grep -v negmatch | grep stuff
I don't think there is any easily-typed equivalent workflow with non-useless cat.
- jpxw 7y agoIf you’re working with a lot of data you probably want to pipe it into head anyway, initially, so <file head -n50 | whatever Can be the starting command. When you no longer need the head there, just get rid of “head |”. Although I agree that the pointing out of “useless cat” is usually not particularly useful or constructive.
- robertelder 7y agoUsing head when there's lots of data make sense, but I really don't see any advantage to avoiding useless cat. Useless cat is way faster to type and make additions to. I sort of get the feeling that 'useless cat' is really just a fun copypasta kinda like when people like post "I'd just like to interject for a moment. What you're referring to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it..."
- drran 7y agoIt's still good to be aware about `useless cat`, to save some CPU and I/O, when converting one liners into scripts.
- heliodor 7y agoRather than using head and worrying about the size of the file, it is easier to simply use "useless" cat then ctrl-c the stream of data that comes out.