From owner-freebsd-questions@FreeBSD.ORG Tue Nov 11 20:37:25 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16F441065679 for ; Tue, 11 Nov 2008 20:37:25 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from mail.rachie.is-a-geek.net (rachie.is-a-geek.net [66.230.99.27]) by mx1.freebsd.org (Postfix) with ESMTP id EADC88FC16 for ; Tue, 11 Nov 2008 20:37:24 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from localhost (mail.rachie.is-a-geek.net [192.168.2.101]) by mail.rachie.is-a-geek.net (Postfix) with ESMTP id CF118AFC1C7; Tue, 11 Nov 2008 11:37:23 -0900 (AKST) From: Mel To: freebsd-questions@freebsd.org Date: Tue, 11 Nov 2008 21:37:19 +0100 User-Agent: KMail/1.9.7 References: <30fc78250811111017l5f087dc8o52c1f1367e056ecd@mail.gmail.com> <200811111936.23400.fbsd.questions@rachie.is-a-geek.net> <86zlk6yr2e.fsf@chameau.maisel.enst-bretagne.fr> In-Reply-To: <86zlk6yr2e.fsf@chameau.maisel.enst-bretagne.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200811112137.21263.fbsd.questions@rachie.is-a-geek.net> Cc: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Perrin?= , Aggelidis Nikos Subject: Re: Using grep to search a repository X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Nov 2008 20:37:25 -0000 On Tuesday 11 November 2008 20:56:41 Fr=C3=A9d=C3=A9ric Perrin wrote: > Le Mardi 11 =C3=A0 19:36, Mel a =C3=A9crit : > > On Tuesday 11 November 2008 19:17:28 Aggelidis Nikos wrote: > >> Hi to all the list, > >> > >> i have a project with a lot of bash scripts in a folder hierarchy.I > >> haven't wrote the project myself so many times i have to search for > >> the definition of a function. For this purpose i decided to use grep > >> {recursively}. > >> The problem is that the project is an svn repository... so grep > >> returns results from .svn and it is really messes up the outcome of > >> grep. I tried bypassing the problem using the `--exclude=3Dfile_patter= n' > >> but since its use is for files not directories it doesn't work.... So > >> the questions are: > >> > >> 1) Can i bypass certain directories{i.e. '.svn' or 'log/'}, using > >> grep? {or a combination of tools + grep} > > > > man find(1), specifically -path and -exec arguments. Example: > > > > find . -type f \( \! -path '*/.svn/*' -a \! -path '*/log/*' \) \ > > -exec grep foo {} + > > FWIW, when doing a similar search, the command built by emacs is (a > longer version of) the following : > > find . \( -path \*/.svn -o -path \*/log \) -prune -o -type f \( -name > \*.sh\* \) -exec grep -i -nH -e pattern {} /dev/null \; > > Isn't "-path .svn -prune" more efficient than "! -path .svn"? I mean, > with the second one, won't find also descend into .svn folders, only to > find that all files have a path containing .svn? Yes, you are correct. It's merely habit that I use ! -path vs -prune. Tip: The microseconds you win by using prune are insignificant to the minutes yo= u=20 add by ending with a semicolon, rather then a + sign. With a semi-colon, a fork is done for each positive match. With a plus sign= =20 matches are bundled till the max command length is met. =2D-=20 Mel Problem with today's modular software: they start with the modules and never get to the software part.