3

I am trying to figure out how to search for "_iterator_tag" string in all sub directories recursively and in files with extensions .cpp, .h, .hpp, .cxx, .inl for now all I can do is search each of these file types separately as below grep -R "_iterator_tag" --include '*.cpp' Is there a quicker way to search all of these file types together? Thank you

4 Answers 4

4

use ack. It's great for searching source code (and not looking in images, or RCS artifacts, like .svn directories)

3

You can specify multiple instances of --include on the command line (they are "or"ed together).

Edit: Specifically

 grep -r --include '*.cpp' --include '*.h' --include '*.hpp' --include '*.cxx' --include '*.inl' "_iterator_tag" /some/path
0

try

find /some/path -name \( '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name '*.cxx' -o -name '*.ini' \) | xargs grep "_iterator_tag"
0

I define the following aliases in my .bashrc

ffg() { eval find $1 | xargs -n 1 grep -nH $2 2>/dev/null ; }
fc() { ffg "-name \*.c -o -name \*.cpp" "$*"; }
fh() { ffg "-name \*.h -o -name \*.hpp" $* ; }
fch() { ffg "-name \*.c -o -name \*.cpp -o -name \*.h -o -name \*.hpp" $* ; }

So I'd typically do:

cd <root subdir>    
fch _iterator_tag

Of course you'd need a different set of file types.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .