4 ms·
This is not about "code golfing", the "sort|uniq -c|sort" combo is in the hall of fame of great code lines. The PATH thing in my script was an unnecessary dist
by enriquto 6y ago
This is not about "code golfing", the "sort|uniq -c|sort" combo is in the hall of fame of great code lines. The PATH thing in my script was an unnecessary distractor, consider this:
file -b /bin/* /usr/bin/* |cut -d' ' -f-2|sort|uniq -c|sort -n
There are no bizarre escapes nor anything. Besides, the "file" program is called only once. The python equivalent that you wrote may be better if you want to store it somewhere, but it takes a lot to type, and it serves a different purpose. The shell line is something that you write once and run it because it falls naturally from your fingers. Moreover, you can run it everywhere, as it works in bash, zsh, pdksh and any old shell. The python version requires an appropriate python version installed (3 not 2).
- viraptor 6y ago> Moreover, you can run it everywhere Issue 1: `zsh: argument list too long: file` Issue 2: `file -b /usr/bin/apt` returns 3 lines, so the entries you count end up being: 2 /usr/bin/apt (for 1 Mach-O universal Yes, it looks easier, but there are traps.
- marcthe12 6y agofind-xargs combo could have been better. It also prevents the case where you cross arg max
- enriquto 6y agoDefinitely! It is also much slower, though, especially if you need to add "-L 1". I prefer to try first that way, if the argument list is too long, then try xargs. On the other hand, the limitations on the command lenght of modern shells are idiotic. The only limitation should be the amount of available RAM, not an artificially imposed limit.