From owner-freebsd-questions Thu Dec 27 14:34:41 2001 Delivered-To: freebsd-questions@freebsd.org Received: from blacklamb.mykitchentable.net (ekgr-dsl2-77.citlink.net [207.173.226.77]) by hub.freebsd.org (Postfix) with ESMTP id 17FDD37B416 for ; Thu, 27 Dec 2001 14:34:16 -0800 (PST) Received: from tagalong (unknown [165.107.42.196]) by blacklamb.mykitchentable.net (Postfix) with SMTP id 9E84FEE692; Thu, 27 Dec 2001 14:36:34 -0800 (PST) Message-ID: <014501c18f26$9d430970$c42a6ba5@lc.ca.gov> From: "Drew Tomlinson" To: "Joe Clarke" Cc: References: <20011227172121.Q11529-100000@shumai.marcuscom.com> Subject: Re: How To Recursively Search Directory For Text String In Files? Date: Thu, 27 Dec 2001 14:34:13 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-Mimeole: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG ----- Original Message ----- From: "Joe Clarke" To: "Drew Tomlinson" Cc: Sent: Thursday, December 27, 2001 2:23 PM Subject: Re: How To Recursively Search Directory For Text String In Files? > > > On Thu, 27 Dec 2001, Drew Tomlinson wrote: > > > OK, I am beginning to understand the power of FBSD and am sure this is > > possible. I just don't know how to do it. What I want to do is search > > all files in my current directory and all the directories below it for a > > text string and then know what file(s) contains the string. I > > understand that grep will do the search but my knowledge is limited to > > "cat file.txt | grep string". How can I construct a command in tcsh to > > feed each file to cat and then feed it to grep *AND* know the name of > > the file grep found the match? Do I have the right concept? Is there a > > better way to accomplish my goal? > > > > You can do grep -r *, but I prefer: > > find -type f -name | xargs grep > Thank you very much! I *knew* it had to be possible but had not come across xargs yet. It looks like a very powerful tool that will have a lot of uses! Drew > For example: > > find /usr/ports -type f -name Makefile | xargs grep -i snmp > > This would search all Makefiles found anywhere in the /usr/ports tree and > grep case-insensitvely through them for the pattern "snmp". > > Joe > > > Thanks, > > > > Drew > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-questions" in the body of the message > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message