program to count the number of occurrences of a word in a string in UNIX code example
Example 1: count occurrences of word in unix bash
$ grep -o -i needs inspire.txt | wc -l
Example 2: program to count the number of occurrences of a word in a string in UNIX
$ grep -o "pattern" file_name | wc -l