I am working on writing some scripts to grep
certain directories, but these directories contain all sorts of file types.
I want to grep
just .h
and .cpp
for now, but maybe a few others in the future.
So far I have:
{ 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.com
Can anyone show me how I would now add just the specific file extensions?
How about:
There is no -r option on HP and Sun servers, this way worked for me on my HP server
-i is for case insensitive search of string
Should write "-exec grep " for each "-o -name "
Or group them by ( )
option '-Hn' show the file name and line.
Just use the
--include
parameter, like this:that should do what you want.
Syntax notes:
-r
- search recursively-i
- case-insensitive search--include=\*.${file_extension}
- search files that match the extension(s) or file pattern onlyThe easiest way is