Shell script: find files with a filename containing keywords

I just wanted to save a little shell script I wrote that searches a directory for files with a certain filename that contain a certain text string.

if [ $# -ne 3 ]
then
        echo "Usuage: fancyFind.sh   
        exit
fi

directory=$1
filename=$2
keywords=$3

for file in $( find $directory -name $filename )
do
        matches=`cat $file | grep "$keywords"`
        if [ -n "$matches" ]
        then
               echo "$file"
        fi
done
Posted on 27 Aug 05 by Helen Emerson (last updated on 27 Aug 05).
Filed under Sysadmin