Using grep for multiple search patterns

grep -e 'attrib1' -e 'attrib3' file

From the man page :

-e PATTERN, –regexp=PATTERN
Use PATTERN as the pattern. This can be used to specify
multiple search patterns, or to protect a pattern beginning with
a hyphen (-). (-e is specified by POSIX.)

Edit :
Alternatively , you can save patterns in a file and use the -f option :

aman@aman-VPCEB14EN:~$ cat>patt
attrib1
attrib3

aman@aman-VPCEB14EN:~$ grep -f patt test
attrib1:  someval11
attrib3:  someval13
attrib1:  someval21
attrib3:  someval23
attrib1:  someval31
attrib3:  someval33

Leave a Comment