Grep for Multiple patterns

Hi All,

I have a file. I need to find multiple patterns in a row and need those rows to divert to new file.

I tried using grep -e / -E / -F options as given in man.
But its not working.

==> cat testgrep.txt
william,fernandes,xxxxx
mark,morsov,yyyy
yy=,xx=
yyyy=,xxxx==

==> /usr/xpg4/bin/grep -E 'yy xx' testgrep.txt

It gives not output.
==> /usr/xpg4/bin/grep -F 'yy xx' testgrep.txt

I used pattern file as well
==> cat patterngrep.txt
yy\n
xx\n

/usr/xpg4/bin/grep -e patterngrep.txt testgrep.txt

It is not working.

Please let me if we have anyother method of doing it.

Thanks,

Try

/usr/xpg4/bin/grep -E 'yy|xx' testgrep.txt

(or)

egrep 'yy|xx' testgrep.txt

Thanks Mahendra.

It worked.

Mahendra,

I have multiple [patetrns to be checked. There can be additions/reductions in the patterns. I need to use pattern list for that.
Do you have any idea how to use pattern list in a file.

Thanks

Are you looking for this info ?

man grep :

-f pattern_file
Read one or more patterns from the file named by the
path name pattern_file. Patterns in pattern_file are
terminated by a NEWLINE character. A null pattern can
be specified by an empty line in pattern_file. Unless
the -E or -F option is also specified, each pattern
will be treated as a basic regular expression.

You can save all patterns in a file line by line and then

grep -f pattern_file Actual_file

I have pattern file

==> cat pattern
def
bc

Datafile
==> cat testgrep.txt
abc,lmn
def,xyz
ghi,h
jkl

I tried this
==> /usr/xpg4/bin/grep -f pattern testgrep.txt
abc,lmn

==> /usr/xpg4/bin/grep -E -f pattern testgrep.txt
abc,lmn

==> /usr/xpg4/bin/grep -F -f pattern testgrep.txt
abc,lmn

I am not getting the second line which contains def.

Hey Mahendra,

There was some syntax problem.
It worked with paatern file
Datafile
==> cat testgrep.txt
abc,lmn
def,xyz
ghi,h
jkl

==> cat pattern
def
abc

command
==> /usr/xpg4/bin/grep -F -f pattern testgrep.txt
abc,lmn
def,xyz

cool, all the best...

you can use the normal grep itself...

no need for /usr/xpg4/bin/grep -F -f pattern testgrep.txt

just say

grep -f pattern testgrep.txt