Using **Raku** (formerly known as Perl_6) ``` ~$ curl https://www.gutenberg.org/cache/epub/5/pg5.txt > US_Constitution.txt ``` THEN: _Below `grep` followed by `elems` gives the count per "examined unit" of text, wherein for `slurp` the unit is the entire file, `lines` is obvious lines, and `words` is obviously words:_ ``` ~$ raku -e 'slurp.grep(/ :i the /).elems.put;' US_Constitution.txt 1 ~$ raku -e 'lines.grep(/ :i the /).elems.put;' US_Constitution.txt 443 ~$ raku -e 'words.grep(/ :i the /).elems.put;' US_Constitution.txt 681 ``` _Below `match` followed by `elems` gives the count of matches. The "examined unit" doesn't matter so `slurp`, `lines`, and `words` all return the same count:_ ``` ~$ raku -e 'slurp.match(:global, / :i the /).elems.put;' US_Constitution.txt 681 ~$ raku -e 'lines.match(:global, / :i the /).elems.put;' US_Constitution.txt 681 ~$ raku -e 'words.match(:global, / :i the /).elems.put;' US_Constitution.txt 681 ``` _The regex can be improved to only match the free-standing word "the". Word-boundaries (general) are denoted with `<|w>` or `<?wb>`. Alternatively, you can be even more specific and denote `<<` left-word-boundary and/or `>>` right-word-boundary:_ ``` ~$ raku -e 'words.match(:global, / :i <|w> the <|w> /).elems.put;' US_Constitution.txt 519 ~$ raku -e 'words.match(:global, / :i <?wb> the <?wb> /).elems.put;' US_Constitution.txt 519 ~$ raku -e 'words.match(:global, / :i << the >> /).elems.put;' US_Constitution.txt 519 #below, remove `:i` (:ignorecase flag, i.e. adverb): ~$ raku -e 'words.match(:global, / << the >> /).elems.put;' US_Constitution.txt 458 ``` Edit: the foregoing is just a general overview on word-counting with Raku. If you need to analyze JSON files specifically you can use Raku's `JSON::Tiny` or `JSON::Fast` modules. https://docs.raku.org/routine/grep https://docs.raku.org/type/Str#method_match https://raku.org