Lets take the below content as an example
This file is a test file
this file is used to count the word 'file' in this test file
there are multiple occurrences of word file in some lines in this test file
I want to count the word 'file' in the above content.
I'm using the below shell command
cat $filename | sed "s/_/new/g" | sed "s/$word/_/g" | tr -c -d _ |wc -c
Is that ok or any better ideas ..?