That's a good one. It's one of the classic examples of the Unix philosophy and how pipelines can be powerful, although of course not applicable in all cases, and they have their issues too - which often becomes an argument on HN (about text streams vs. object pipes a la PowerShell, etc.).
I had seen it a while ago and blogged about it here, with solutions (approx.) in Python and shell:
The Bentley-Knuth problem and solutions:
https://jugad2.blogspot.com/2012/07/the-bentley-knuth-proble...
Also, previous HN thread about it here:
Revisiting Knuth and McIlroy's word count programs (2011) (franklinchen.com)