Operating System - Linux
1819870 Members
2318 Online
109607 Solutions
New Discussion юеВ

how to grep multiple patterns

 
SOLVED
Go to solution
Padma Asrani
Honored Contributor

how to grep multiple patterns

Hi

My requirement is that I wanted to grep multiple patterns from the output of some command.

For example

Output is

10 Selection Name XXX
44 isInterface TRUE
52 isIP TRUE
53 isIPX FALSE

I wanted to grep the value of Selection name XXX and also isIPF(FALSE) in a single command

Regards
Padma

8 REPLIES 8
Geoff Wild
Honored Contributor

Re: how to grep multiple patterns

egrep

egrep "Selection Name XXX|FALSE"

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor
Solution

Re: how to grep multiple patterns

egrep

command |egrep "Selection Name XXX|FALSE"

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sandman!
Honored Contributor

Re: how to grep multiple patterns

# | grep -E "Selection Name XXX|isIPX FALSE"
Padma Asrani
Honored Contributor

Re: how to grep multiple patterns

Thanks a lot for quick response. It works.

Regards
Padma
James R. Ferguson
Acclaimed Contributor

Re: how to grep multiple patterns

Hi:

# grep -e XXX -e isIPF

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: how to grep multiple patterns

Hi:

# grep -e XXX -e isIPX

Regards!

...JRF...
Padma Asrani
Honored Contributor

Re: how to grep multiple patterns

Thanks a lot to all
Dennis Handly
Acclaimed Contributor

Re: how to grep multiple patterns

As mentioned by several people, there is a -e option just for that. I'd use that over the egrep hammer.

You can also use -f file and put the patterns there. And finally, you can use one long quoted string with embedded newlines:
... | grep "Selection Name XXX
isIPX FALSE"