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

Unfortunately, not all greps have a recursive flag, such as /usr/bin/grep on Solaris. :( I'm forced to create my own recursive grep like this:
grep -li search_term * */* */*/* */*/*/* (etc.)
But I agree that a recursive grep is the best solution for the OP.

Replies are listed 'Best First'.
Re^3: text search in a file
by Tanktalus (Canon) on Aug 11, 2005 at 01:55 UTC

    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. :-)

      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.

      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.
Re^3: text search in a file
by Fletch (Bishop) on Aug 11, 2005 at 02:52 UTC

    Or if you use the most spiffy zsh you can do this:

    grep -li search **/*(.)

    Which will recursively search only files. But again that may bump into a number of arguments limitation (in which case you'd use print -N **/*(.) | xargs grep -li search or the like).

    --
    We're looking for people in ATL