3 ms·
"The unix command line ('cat foo.txt | sort | uniq -c | sort -rn') is wonderfully concise and powerful". And yet, contrary to the author's assertion, it can be
by rflrob 17y ago
"The unix command line ('cat foo.txt | sort | uniq -c | sort -rn') is wonderfully concise and powerful". And yet, contrary to the author's assertion, it can be made even more concise without sacrificing the power:
sort foo.txt | uniq -c | sort -rn
- kalid 17y agoThanks for the comment. Yeah, in this case I decided to keep the "superflous" cat because it offers more flexibility/readability -- i.e., what if you want another command before the first sort? With the 2nd version you have to remove foo.txt and type your command, instead of just inserting "mycommand |" where needed (and what if mycommand doesn't accept a file, just stdin, then you need the cat anyway). But it's a good point, and there's a balance between the absolute minimum and flexibility. At one extreme you have code golf, at the other you have an abstract FactoryFactory.