Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick grep/egrep question!

Status
Not open for further replies.

gringomike

Technical User
Aug 6, 2003
148
GB
Hi All,

What is the grep/egrep command to search for 2 patterns in a "ps -ef" command?

I want to search for all occurances of "pattern 1" and "pattern 2" on the same line.

I thought it was the following but it doesn't work:-(

ps -ef |grep -e 'pattern 1 -e pattern 2'


Help!

Thanks

GM
 
Try something like this:
Code:
ps -ef | grep 'pattern 1' | grep 'pattern 2'

Hope This Help
PH.
 
Thanks for the reply but this doesn't work either:-(

Any other ideas?

GM
 
You want :
ps -ef | egrep "pattern 1|pattern 2"

Dickie Bird (:)-)))
 
dickiebird, your solution will matches all lines with either pattern, not those with the 2 on the same line.
gringomike, can you post an example of your ps -ef listing, the 2 patterns you search for and the expected result ?
 
PH - you're right - I mis-read the problem !
the answer, as you right posted :
ps -ef | grep pattern1 | grep pattern2
But why doesn't it work for gringomike ?

Dickie Bird (:)-)))
 
Thanks for the replies!

The solution was ps -ef | egrep "pattern 1|pattern 2" as posted by dickiebird!

My apologies for not been particularly clear but this is exactly what I was after!

Thanks again!

GM

 
Eh eh gringomike, don't know the diff between AND and OR? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top