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.
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:
I used this today. Thanks. For extra special yumyum I like to do a grep -Hn
By Steve, At 4/25/05 5:06 PM
Mmm, grep -Hn is extra tasty.
By ynniv, At 4/29/05 4:07 PM
Post a Comment
<$I18N$LinksToThisPost>:
Create a Link
<< Home