Operating System - HP-UX
1827817 Members
1906 Online
109969 Solutions
New Discussion

Is it possible to grep two or more patterns ?

 
SOLVED
Go to solution
yc_2
Regular Advisor

Is it possible to grep two or more patterns ?

Hi,

Is it possible to grep two or more patterns ?

eg: I want to grep root, daemon and adm in password file.


Thanks in advance,
YC
7 REPLIES 7
Robert-Jan Goossens
Honored Contributor
Solution

Re: Is it possible to grep two or more patterns ?

Hi,

You can use grep -e

# cat /etc/passwd | grep -e root -e daemon -e adm

Robert-Jan.
Tim Adamson_1
Honored Contributor

Re: Is it possible to grep two or more patterns ?

Hi,

Yes, Try :

# grep -e root -e adm -e daemon /etc/passwd


Cheers!
Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Michael Tully
Honored Contributor

Re: Is it possible to grep two or more patterns ?

$ cat /etc/passwd | grep root | grep daemon | grep adm
Anyone for a Mutiny ?
Tim D Fulford
Honored Contributor

Re: Is it possible to grep two or more patterns ?

Yes, you can grep two or more patterns in one go

1 - grep -e -e ... ...

2 - egrep "|||..." ....

I prefer method 2 as it is less typing

Regards

Tim
-
blal
Frequent Advisor

Re: Is it possible to grep two or more patterns ?

Hi


U can use egrep , which is extended grep .

syntax is

cat passswd |egrep -i 'root|daemon|adm'


Regds,
baiju
Live and let live.
vasundhara
Frequent Advisor

Re: Is it possible to grep two or more patterns ?

Hi,

egrep is the best way. you can refer man page for more options.

Regards
VJ.
twang
Honored Contributor

Re: Is it possible to grep two or more patterns ?

# grep -E 'root|daemon|adm' /etc/passwd