Grep Linux basics command help

I need some Linux grep command basics help. What I need to do is find out how many times a word appeared in text file. Right now I run grep command:

grep 'my-word' file

It shows me 100s of line. Instead of I need to show a count of ‘my-word’ and store in Linux shell variable.

The grep command searches for words or string in each FILE. You need to run the grep command following:

grep -c 'my-word' file


-c option suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option, count non-matching lines.

I strongly suggest that you read the following grep tutorial:


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki