home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / sgi / 12637 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.8 KB

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