for pattern in ./patterns/* ; do matches=0 find $dirname -type f -name "$filename*.txt" | while read page; do matches_page=`grep --file=$pattern "$page" | wc -l` matches=$(($matches + $matches_page)) echo $matches $matches_page done echo "$matches for $pattern" done --- output ---------- Filename 07-26-2007 08;10;56AM 16 16 30 14 0 for ./patterns/commbank