using grep for a dummy

Hi there;

I am really new in unix. I need some help regarding use of grep command.

I need to write a shell script which takes a C++ program and counts the
number of words which could be a valid C++ variable name.

I wrote a regular expression to find c++ variable names:

^[_a-zA-Z][a-zA-Z0-9]*

but it prints just lines. How can apply this command to a word, I mean I want to list the words and count themm.

can anyone help me?

always check your man page. man grep to see if there are options that support matching whole words...

thanks for your suggestion, I am aware of that there is manual option and I can get information about commands. I didnot ask that there is a man page or not! I asked something about what I want to do.. If you dont know it ot If you dont share your knowladge, u dont have to write.

thanks.

This is strictly not encouraged in the forum.

Please do read the rules of the forum.

to grep as a word and not as a pattern match use ' -w ' option of the grep