The "grep" and "wc" commands that are included in that table don't attempt to solve the problem. That wasn't clear to me on first reading.
I suppose they are included as a baseline for reading a file and for tokenising strings into words. See https://github.com/benhoyt/countwords/blob/eb2a8adf21c895907...