[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: searching inside files with find, cat and grep as a oneliner ...



Hi Albrecht,
On Fri, Sep 17, 2010 at 06:08:18PM +0000, Albretch Mueller wrote:
>  search for files using a pattern (say all files with a certain extension)
>  then search inside each of the found files for a word or regexp pattern
>  You could do this using find, cat and grep in a script, but I was
> wondering about how could you do it with a oneliner

You could do it with a line like
find / -name filename -exec grep word {} \;

this will search for all files with the name "filename" and then use
"grep" in order to search for the expression "word" in this file.
The line outputs the grep-results.
You could also just output the filenames by using
find / -name filename -exec grep -l word {} \;

For more details, see "man find" and "man grep"  ,-)

Axel


Reply to: