From: alan@nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward Inodes.)
Subject: Re: UNIX command to search subdirs for text in a file
Date: 1997/01/14 [thread overview]
Message-ID: <5bh1hf$5ur@nntpd2.cxo.dec.com> (raw)
In-Reply-To: 01bc018d$8f170bc0$17ee1bac@usbgrjeff
In article <01bc018d$8f170bc0$17ee1bac@usbgrjeff>, "Jeff Shervey" <jeff.shervey@us.landisstaefa.com> writes:
>
>With DEC UNIX 3.2 how can I search a bunch of subdirectories for a certain
>file that contains certain text.
find . -name '*.sql' -print | xargs grep -i duplicate /dev/null
Starting at the current directory, find search for all the files
with names of the form <anything>.sql and print the names to
stdout. This is written a copy xargs which collects as many
names as will fit on a command line and executes the command
"grep -i ..." with that file list. The use of /dev/null as
the first name of the name ensures that grep will always print
the file name, since it typically doesn't if there is only one
file name in the list. THere may be a grep option to provide
this feature.
If you're interested in what your commands were actually trying
to do...
>I'm trying this command with no luck:
>
>grep -i "duplicate" | find . -name *.sql -print
Do an case insensitive search for the string duplicate reading
from stdin and pipe that to the indicated find command. Not
that find ever reads anything from stdin.
>
>I've also tried:
>
>find . -name *.sql -print | grep -i "duplicate" *.pls
Find all the indicated names and write them to grep's stdin. Were
it not for the *.pls, this would search the file *names* for the
text "duplicate". But since this grep has been handed a file
wildcard of *.pls, that will be expanded by the shell and those
files will be used instead of the text from stdin.
It is also worth noting that the sequence "-name *.sql" won't
search for the names of the form <anthing>.sql. The shell does
the expansion of *.sql so the -name option will get the first
of that expansion and the rested will be treated by find as
options, which it will probably complain about. For example,
if you had a.sql and b.sql, find would see:
find . -name a.sql b.sql -print
By quoting '*.sql' the shell won't expand it and find will know
what to make of the wildcard.
>
>Thank you,
>jeff.shervey@us.landisstaefa.com
>
>--
>These comments do not necessarily reflect the views of Landis & Staefa, Inc.
>
--
Alan Rollow alan@nabeth.cxo.dec.com
next prev parent reply other threads:[~1997-01-14 5:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-01-13 5:00 UNIX command to search subdirs for text in a file Jeff Shervey
1997-01-13 5:00 ` Mark Sirota
1997-01-14 5:00 ` Alan Rollow - Dr. File System's Home for Wayward Inodes. [this message]
1997-01-14 5:00 ` Steve Strange USG
1997-01-14 5:00 ` Kenneth Miller
1997-01-14 5:00 ` Gleb O. Raiko
1997-01-15 5:00 ` Juergen Fuhrmann
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox