I’m working on a script to grep certain directories:
{ grep -r -i CP_Image ~/path1/;
grep -r -i CP_Image ~/path2/;
grep -r -i CP_Image ~/path3/;
grep -r -i CP_Image ~/path4/;
grep -r -i CP_Image ~/path5/; }
| mailx -s GREP email@domain.example
How can I limit results only to extensions .h and .cpp?
Just use the
--includeparameter, like this:That should do what you want.
To take the explanation from HoldOffHunger’s answer below:
grep: command-r: recursively-i: ignore-case-n: each output line is preceded by its relative line number in the file--include \*.cpp: all *.cpp: C++ files (escape with \ just in case you have a directory with asterisks in the filenames)./: Start at current directory.