Grep Linux basics command help

shell
unix
grep
linux

#1

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.


#2

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

grep -c 'my-word' file

Where,

-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:


And