in reply to Searching word(s) in multiple file and directories

non-Perl unix approach:

find . -exec fgrep variable_name {} /dev/null ;

Of course, you can substitute any directory for '.'; you need to surround fgrep's argument with single-quotes if it has shell-interpretable characters like '$'; you can use grep instead of fgrep to search by regexp instead of for plaintext.

I have this in my .bashrc:

rfind() { find . -exec fgrep $1 {} /dev/null \; }

Replies are listed 'Best First'.
Re: Re: Searching word(s) in multiple file and directories
by simonm (Vicar) on Dec 03, 2003 at 21:12 UTC
    FWIW, some flavors of grep handle recursion on their own with the -r flag; check your local manpage for confirmation or just try it:
    fgrep -r variable_name .
      Just what I was looking for. thanks.
Re: Re: Searching word(s) in multiple file and directories
by waswas-fng (Curate) on Dec 03, 2003 at 23:19 UTC
    Or to just print the filenames with the matching text:
    find /path -type f -exec grep -l "StringToMatch" "{}" \;
    from there you can pipe on and actually do something with the output. Note that the -l is a lowercase L.


    -Waswas