Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Dec 2001 18:18:15 +0100
From:      Roman Neuhauser <neuhauser@mobil.cz>
To:        smorton@acm.org
Cc:        FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: [Fwd: Re: How To Recursively Search Directory For Text String In Files?]
Message-ID:  <20011228181815.S476@roman.mobil.cz>
In-Reply-To: <3C2C98D6.2080103@verizon.net>
References:  <3C2C98D6.2080103@verizon.net>

next in thread | previous in thread | raw e-mail | index | archive | help
> Date: Fri, 28 Dec 2001 11:07:50 -0500
> From: Simon Morton <simon.morton@verizon.net>
> To: FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
> Subject: [Fwd: Re: How To Recursively Search Directory For Text String In Files?]
> 
> Roman Neuhauser wrote:>>From: "Drew Tomlinson" <drew@mykitchentable.net>
> >>To: <questions@freebsd.org>
> >>Subject: How To Recursively Search Directory For Text String In Files?
> >>Date: Thu, 27 Dec 2001 14:19:42 -0800
> >>
> >>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?
> >>
> >
> >     Hi there,
> >
> >     the other suggestions are insanely complicated IMO. All you need is
> >     > grep -FIHnir pattern path
> >             ^^^^^^- recursive search
> >             ||||'-- case insensitive search
> >             |||'--- report the line number
> >             ||'---- report the file name
> >             |'----- ignore binary files
> >             '------ the pattern is a fixed string
> >     > grep -FIHnir freebsd ~/Mail
> >
> >
> 
> That's the first time I have heard the Unix philosophy described
> as "insanely complicated".  The whole beauty of the Unix approach
> is that you combine simple, specialized, commands together using
> pipes in order to perform complex tasks right on the command line.
> 
> Your solution is a dead end.  What if you wanted to refine your
> search to match only files with a certain extension or pattern in
> the name?  What if you wanted to match only files which had been
> modified within a certain period of time?  What if you wanted to
> delete or perform some other action on matching files?  Are you
> going to add keep adding more options to grep?
> 
> That way lies the insane complexity, my friend.

    I think you should pay a wee bit more attention to what you read:

    "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."

    Simple task, simple solution. I don't know what good would the
    original poster achieve by using find, xargs and grep where simple
    grep does the work. Of course, it's easy to get carried away, but
    one should discriminate between use and abuse.

-- 
FreeBSD 4.4-STABLE
6:12PM up 2 days, 4:50, 11 users, load averages: 0.02, 0.05, 0.01

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011228181815.S476>