in reply to Re^2: text search in a file
in thread text search in a file

Nah - much easier to do something like:

grep -li search_term `find . -type f`
Assuming there aren't so many files that you exhaust the command shell line length. Or you can check out xargs, or even -exec option on find.

TMTOWTDI - even in shell. :-)

Replies are listed 'Best First'.
Re^4: text search in a file [OT]
by graff (Chancellor) on Aug 11, 2005 at 11:35 UTC
    Alas, in addition to having no recursive option in /usr/bin/grep, Solaris also offers the inability to use /usr/bin/find and /usr/bin/xargs like this:
    find . -print0 -type f | xargs -0 grep -li search_term
    at least, not in SunOS 5.8 -- I don't know if this has been fixed in more recent releases, but if it hasn't... well, I just don't understand what's wrong with those people at Sun.

    Solaris users generally benefit from having the GNU tools installed in /usr/local/bin, and putting that in front of /usr/bin in their shell PATH.

Re^4: text search in a file
by davis (Vicar) on Aug 11, 2005 at 09:28 UTC
    While we're on shell stuff, I've got to point out that that doesn't work if there's a lot of files below your current working directory. It'll fail with "argument list too long". Much better is:
    $ find . -type f -exec grep -qi search_term {} \; -print
    cheers

    davis
    Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.

      Even better if you want to optimize the number of sub-processes that get forked:

      find . -type f -print | xargs grep -qi

      /J\

      Thanks! That's a lot nicer to use than what I posted.

      Just FYI, Solaris' built-in grep doesn't like the q flag. This seems to work well:
      find search_path -type f -exec grep -li search_term {} \;
      Also, at least on Solaris, that -print causes double output.