I have a large JSON file that is on one line, and I want to use the command line to be able to count the number of occurrences of a word in the file. How can I do that?
One can even save the
If it is not guaranteed that there are spaces between the words, you have to use some other character (as delimiter) to replace. For example alternative tr parts are
if you want to replace double or single quotes.
In case you need to count WORD but not prefixWORD, WORDsuffix or prefixWORDsuffix, you can enclose the WORD pattern in word-begin/end markers:
|show 1 more comment|
With GNU grep,
$ python -c 'import this' | grep '\<one\>' There should be one-- and preferably only one --obvious way to do it. Namespaces are one honking great idea -- let's do more of those! $ python -c 'import this' | grep -o '\<one\>' one one one $ python -c 'import this' | grep -o '\<one\>' | wc -l 3
With recent versions of GNU
should work. (Earlier versions had a bug in this combination of options.)