When trying to get some info from a text file, or command output people tend to do something like;
$ cat somefile.txt | grep something | wc -l
This would spit out the contents of somefile.txt, pipe it into grep to filter out just "something" and then count how many lines contain that "something", perfectly a normal thing to do, but it's so bloated and
irks me to no end. Instead of this overly bloated command one-liner,
this can all be achieved in just a simple one command;
$ grep -c something somefile.txt
I think I've been guilty on doing that on the occasion. Completely forgetting that I can just simple feed grep the text file...but
in my defense I do not make YT or any other video tutorials LOL
But yes, I agree, any one that "teaches" this stuff should know better.
Oh and BTW , I've started eliminating the empty space right after the pipe character. I blame that on you ;)
When trying to get some info from a text file, or command output people tend to do something like;
$ cat somefile.txt | grep something | wc -l
This would spit out the contents of somefile.txt, pipe it into grep to filter out just "something" and then count how many lines
contain
that "something", perfectly a normal thing to do, but it's so bloated and irks me to no end. Instead of this overly bloated command
one-liner, this can all be achieved in just a simple one command;
I dunno, that's just me, my quirkiness lol. Don't judge me =)
$ cat somefile.txt | grep something | wc -l
$ grep -c something somefile.txt
Something I've seen lots of people do in examples/videos/tutorials keeps on grating on me, and I thought I would share my frustration
When trying to get some info from a text file, or command output people tend to do something like;
$ cat somefile.txt | grep something | wc -l
this can all be achieved in just a simple one command;
$ grep -c something somefile.txt
they are assuming the role of a "teacher" of sorts, and should
know better.
While you are totally right that the latter is much shorter and might
also be quicker, you have to _know_ and _remember_ that grep is able
to count on its own.
Whereas knowing that "-c" in grep can count the occurances of a
certain thing in a file is kind of a one-off knowledge that might be forgotten sooner than later...
Am 11.01.22 schrieb MeaTLoTioN@1337:1/101 in TQW_LINUX:
Hallo Meatlotion,
While you are totally right that the latter is much shorter and might also be quicker, you have to _know_ and _remember_ that grep is able
to count on its own.
So this is "old school" or somebody who was taught "old school".
of single functional tools" - in that you can combine the tools together t a complex job done - without having to write that complex tool.
Sysop: | Shaun Ewing |
---|---|
Location: | Blue Mountains, Australia |
Users: | 196 |
Nodes: | 16 (0 / 16) |
Uptime: | 214:29:44 |
Calls: | 154 |
Files: | 187,818 |
Messages: | 331,109 |