As a side note, I think the shell script version would have been multicore friendly, at least up to six cores. I am sure Knuth's was single threaded.
Finally, to your point on horrible hacks, maybe Knuth's version dealt with a whole bunch of edge cases in each, like for instance dealing with dos/unix/mac endlines. But, probably not -- it was a toy program written as evangelism and out of courtesy. sort and uniq et al embed many programmer lifetimes of experience and bug fixing at this point. Getting all of that nearly for free is really, really great.
No, it has function calls instead.
> I think the shell script version would have been multicore friendly
Not unless 'sort' is implemented very cleverly.
> maybe Knuth's version
We'll never know unless someone manages to dredge up the source code.
But the specifics on Knuth's version are not really the point. Someone else might have been able to do better. And someone using a less brain damaged language that Pascal might have been able to do even better. In fact, here it is in four lines of Common Lisp (using Ergolib - https://github.com/rongarret/ergolib):
(defun histogram (path)
(bb l (split (file-contents path) t :test (fn (a b) (whitespacep b)))
l (sort 'string< (mapcar 'string-upcase (remove "" l)))
(for item in (remove-duplicates l) collect (list item (count item l)))))
Writing a pure CL version is left as an exercise. My guess is it would be 10-20 LOC.That's not how the sort command, in lines 3 and 5, works.