3 ms·
My first reaction was to wonder why `tr` was required at all - neither conversion struck me as necessary. These days both `sort` and `uniq` can do case-insensit
by darrenf 8y ago
My first reaction was to wonder why `tr` was required at all - neither conversion struck me as necessary. These days both `sort` and `uniq` can do case-insensitivity:
sort -f | uniq -ic
So I just allow the shell to do word splitting:
for x in `cat foo.txt` ; do echo $x ; done | sort -f | uniq -ic | sort -rn | head -<num>
- ColinWright 8y agoDoesn't that have different behaviour if there is punctuation in the file? On my phone and not in a position to test it, so I'm not sure, but I think it's different.
- darrenf 8y agoIt does indeed. Good catch :)
- xorcist 8y agoDon't abuse command line parameters just to do word splitting. There's at least a dozen obvious ways to do that without leaving your reader guessing what that loop does. Avoid being clever. If you want to change word separators to line separators then just do that (with tr, sed, or some other way) and the purpose will be obvious. And please be mindful of looping over user supplied data like that. Those things are typically the ones that works fine in test but blow up in production. The environment has a maximum size, and you shouldn't store large amounts of data there.