home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.sgi:12637 comp.sys.mips:892 comp.unix.misc:3298 comp.unix.questions:10191
- Newsgroups: comp.sys.sgi,comp.sys.mips,comp.unix.misc,comp.unix.questions
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!odin!fido!sam!pj
- From: pj@sam.wpd.sgi.com (Paul Jackson)
- Subject: Re: Summary of (Re: Grep-ing for Constants (Re: Assembler Syntax...))
- Message-ID: <opn11fo@fido.asd.sgi.com>
- Sender: news@fido.asd.sgi.com (Usenet News Admin)
- Organization: Silicon Graphics, Inc. Mountain View, CA
- References: <1992Aug18.060851.11721@leland.Stanford.EDU> <1992Aug19.235443.21099@leland.Stanford.EDU>
- Date: Thu, 20 Aug 1992 01:13:37 GMT
- Lines: 32
-
-
- In article <1992Aug19.235443.21099@leland.Stanford.EDU>, underdog@leland.Stanford.EDU writes:
- > >Is there a way to use grep (or some other command)
- > >to do the search across all files at my current level of the directory
- > >_and_ subdirectories below the current level--all at once?
- >
- > I received numerous replies.
- >
- > The one with the simplest explanation was
- >
- > Try:
- > find . -exec grep your_string {} \; -print | pg
-
-
- I would recommend against using the -exec option of find in many
- cases, because it is slow - requiring a fork/exec per file.
-
- Consider:
-
- find . -print | xargs file |
- grep 'text$' | sed 's/:.*//' |
- xargs grep your_string /dev/null
-
- The file command shows the "type" of a file, and it happens that
- it always has the word "text" at the end of the description for
- just text files. The xargs command runs a command with several
- arguments collected from stdin. The extra /dev/null on the grep
- command causes it to always show the filename, even in the case
- that only one actual file is searched. The sed command is used
- to strip off the trailing "type" stuff that the file command
- put on each filename. Clever use of sed can handle the work
- done by the grep, but that requires too much thinking.
-