Re: grep question


Subject: Re: grep question
From: Paul Warren (pdw@ferret.lmh.ox.ac.uk)
Date: Sun Feb 27 2000 - 10:31:01 CST


On Sun, 27 Feb 2000, Daniel Weber wrote:

> I want to search the source tree for certain strings, but only certain
> types of files (e.g. cpp or h files). grep has a --recursive option,
> but it doesn't allow you to specify a file extension with that option,
> so it searches all files, including the obj and binary files which takes
> forever. Is there a way to limit a grep search to an extension, or do I
> have to write a tiny shell script that does it? This is such a common
> thing to do, I'm sure I'm missing something....

find is your friend here. You'll want to look at the manpage, but
for starters:

        find ./ -name foo.bar -exec grep 'needle' {} \; -print

It's a bit of a mouthfull so you'll probably want to put it into a shell
function anyway...

Paul



This archive was generated by hypermail 2b25 : Sun Feb 27 2000 - 10:31:06 CST