find then grep

I have some patterns that I need to match with the content of several files and I'm having trouble to do it

Here is what I tried already :

ksh won't even execute this

#!/bin/ksh
path="/export/home/ipomwbas"
pattern=$path"/flags"
find . -name "*.properties" |\
while read file; do
  /usr/xpg4/bin/grep -f $pattern $file | cat >> results
done

and this doesn't give me the expected output:

find . -name "*.properties" | xargs /usr/xpg4/bin/grep -f flags | cat >> results

Why not simply use grep instead of the xpg4 version and there is no need for that cat process either...

find . -name "*.properties" | xargs grep -f flags >> results

I tried without the xpg4 version of grep, but it gives : grep: illegal option -- f

find . -name "*.txt" | xargs grep pattern | sed 's/^.*\.txt://' | cat  >> c

@summer_cherry

I modified your suggestion to fit my situation like this :

find . -name "*.properties" | xargs /usr/xpg4/bin/grep -f flags | sed 's/^.*\.properties://' | cat  >> c

but it gave me weird results. There was a lot of entries in the file, but none of them contained patterns from my flags file, like :

PROPERTIES_PATH         = c:/java/SM_Web/config/

I don't know if this can help you, but this is the content of my flags file

.*\.host\=
.*\.port\=
.*\.url\=
.*\.schema\=
.*\.user.*
.*\.password\=
.*\.simulator.flag.*

This is working for me on Ubuntu (with regular expression syntax in my pattern file).

find . -iname '*.ext' | xargs egrep -f patterns.txt

The find didn't work because of the -iname argument

Just try -name then. The -iname is just a case-insensitive version. If you know your extensions will always be lower-case (for example), then don't worry about -iname.