How to recursively search for a list of keywords in a given directory?

Hi all,
how to recursively search for a list of keywords in a given directory??

for example:
suppose i have kept all the keywords in a file called "procnamelist" (in separate line)
and i have to search recursively in a directory called "target/dir"

if i am not doing recursive search then the below command is working.

fgrep -if  procnamelist target/dir/*

but when i am using the below command for the recursive search, its throwing error as "bad option -r"

fgrep -rif  procnamelist target/dir/*

or

fgrep -Rif  procnamelist target/dir/*

not working.

please help .:frowning:
[/COLOR]

Perhaps:

cat procnamelist|while read line;do fgrep -Rif $line target/dir/*;done

@glev2005 not working i am getting same error as :fgrep: illegal option -- R
actually the r option is not there in fgrep.. any other way??

while true
do
while read line
do
cat file | grep "$line" 
done<procnamelist
done

Whenever you need to traverse the a filesystem but the command does not support -R/r, think find(1).

find target/dir -type f -exec grep -iFf procnamelist /dev/null {} \;

If your find is compliant with the POSIX 2004 edition or later, use + to increase efficiency:

find target/dir -type f -exec grep -iFf procnamelist /dev/null {} +

That would have failed even if -[r|R] were supported. A line from procnamelist, which is a pattern to match, is treated as a filename argument to -f. If you put procnamelist where it belongs, after -f, the pipe and while loop serve no purpose.

The sole reason for the existence of this thread is file system traversal. This proposal is an infinite loop that reads one file over and over and over and ...

Regards,
Alister