From: rvaede on

I want to find a word in a text file but I want to search for this
info in a whole directory which also has sub directory.

I want to avoid using this:

grep data file1
grep data file2
grep data file3
From: pk on
rvaede wrote:

>
> I want to find a word in a text file but I want to search for this
> info in a whole directory which also has sub directory.
>
> I want to avoid using this:
>
> grep data file1
> grep data file2
> grep data file3

find /basedir -type f -exec grep -- word {} +

or some variation thereof.

Also GNU grep has an option -r that can recurse into subdirectories.

From: Lew Pitcher on
On June 11, 2010 14:45, in comp.unix.shell, rvaedex23(a)gmail.com wrote:

>
> I want to find a word in a text file but I want to search for this
> info in a whole directory which also has sub directory.
>
> I want to avoid using this:
>
> grep data file1
> grep data file2
> grep data file3

Depending on your version of grep, you might be able to perform "recusive
grep". The GNU grep offers a -R (or -r or --recursive
or --directories=recurse) option that recursively searches directories for
files with matching grep values

GREP(1) GREP(1)

NAME
grep, egrep, fgrep - print lines matching a pattern

SYNOPSIS
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
Grep searches the named input FILEs (or standard input if no files
are named, or the file name - is given) for lines containing a match
to the given PATTERN. By default, grep prints the matching lines.

In addition, two variant programs egrep and fgrep are available.
Egrep is the same as grep -E. Fgrep is the same as grep -F.

OPTIONS

...

-R, -r, --recursive
Read all files under each directory, recursively; this is
equivalent to the -d recurse option.

Perhaps you can use this to solve your problem.

--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------


From: rvaede on
On Jun 11, 2:58 pm, Lew Pitcher <lpitc...(a)teksavvy.com> wrote:
> On June 11, 2010 14:45, in comp.unix.shell, rvaede...(a)gmail.com wrote:
>
>
>
> >    I want to find a word in a text file but I want to search for this
> > info in a whole directory which also has sub directory.
>
> > I want to avoid using this:
>
> > grep data file1
> > grep data file2
> > grep data file3
>
> Depending on your version of grep, you might be able to perform "recusive
> grep". The GNU grep offers a -R (or -r or --recursive
> or --directories=recurse) option that recursively searches directories for
> files with matching grep values
>
> GREP(1)                                                              GREP(1)
>
> NAME
>        grep, egrep, fgrep - print lines matching a pattern
>
> SYNOPSIS
>        grep [options] PATTERN [FILE...]
>        grep [options] [-e PATTERN | -f FILE] [FILE...]
>
> DESCRIPTION
>        Grep  searches the named input FILEs (or standard input if no files
>        are named, or the file name - is given) for lines containing a match
>        to the given PATTERN.  By default, grep prints the matching lines.
>
>        In addition, two variant programs egrep and fgrep are available.
>        Egrep is the same as grep -E.  Fgrep is the same as grep -F.
>
> OPTIONS
>
>        ...
>
>        -R, -r, --recursive
>               Read all files under each directory, recursively; this is
>               equivalent to the -d recurse option.
>
> Perhaps you can use this to solve your problem.
>
> --
> Lew Pitcher
> Master Codewright & JOAT-in-training   | Registered Linux User #112576
> Me:http://pitcher.digitalfreehold.ca/| Just Linux:http://justlinux.ca/
> ----------      Slackware - Because I know what I'm doing.         ------

Unfortunately I cannot use -R option.
From: Thomas 'PointedEars' Lahn on
rvaede wrote:

> Lew Pitcher wrote:
>> rvaede...(a)gmail.com wrote:
>> > I want to find a word in a text file but I want to search for this
^^^^^^^^^ ^^^^^^
>> > info in a whole directory which also has sub directory.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> > I want to avoid using this:
>> >
>> > grep data file1
>> > grep data file2
>> > grep data file3
>>
>> [...]
>> NAME
>> grep, egrep, fgrep - print lines matching a pattern
>> [...]
>> -R, -r, --recursive
>> Read all files under each directory, recursively; this is
>> equivalent to the -d recurse option.
>>
>> Perhaps you can use this to solve your problem.
>
> Unfortunately I cannot use -R option.

man find
man grep

And read <http://www.netmeister.org/news/learn2quote.html> while you are at
it.


PointedEars