6 ms·
Apart from the useless use of cat, since sort does the work here something like the following would probably suffice: grep ERROR logfile | cut -f 1 -d ' ' | so
by xorcist 7y ago
Apart from the useless use of cat, since sort does the work here something like the following would probably suffice:
grep ERROR logfile | cut -f 1 -d ' ' | sort | uniq -c
- j_z_reeves 7y agoyes that would also work! I forgot about the `-c` argument for uniq.
- j0057 7y agoThere's really nothing useless about that use of cat: it makes the pipeline compose better from left to right. It's not like you have to pay 25 cents for each process you spawn.
- xorcist 7y agoSo does the pipeline above. It's not detrimental to performance since an empty cat is a no-op in a pipeline. You can have any number of them. But commands should be written for humans to understand, and inserting no-ops is a distraction to the reader. In the trivial example, "grep needle haystack" reads better than "cat haystack | grep needle".