trust your technolust

Monday, April 11, 2005

Pearls of Unix

Sometimes, you really need to find something in a type of file. Grep -r is often too slow because of other large files in the same directory as your source. Here's one solution to the problem:

find . \( -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' \) -exec grep -H searchstringhere {} \;

This will limit your search to .c, .cpp, and .h while still showing the filename of any matches (grep's -H option). Unfortunately, Windows has heavy processes that take much much longer to spawn than *nix... Since each found file spawns a grep process, this optimization might not save you any time under Cygwin.

2 Comments:

Anonymous Steve said...

I used this today. Thanks. For extra special yumyum I like to do a grep -Hn

5:06 PM

 
Blogger ynniv said...

Mmm, grep -Hn is extra tasty.

4:07 PM

 

Post a Comment

<< Home