grep for more than one pattern | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

grep for more than one pattern

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-13-2005
frustrated1 frustrated1 is offline
Registered User
 
Join Date: Aug 2003
Last Activity: 11 March 2013, 8:46 AM EDT
Location: Ireland
Posts: 295
Thanks: 2
Thanked 1 Time in 1 Post
grep for more than one pattern

I want to grep for more than one pattern in a file...

ie.. grep for root and nobody in /etc/passwd file and then count the occurances..

Ideally I would want to do this but I know it doesnt work
grep -c root nobody /etc/passwd


Any ideas?
Sponsored Links
    #2  
Old 12-13-2005
Raom Raom is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 21 May 2009, 5:39 AM EDT
Location: india
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
look at -e option with grep
Sponsored Links
    #3  
Old 12-13-2005
frustrated1 frustrated1 is offline
Registered User
 
Join Date: Aug 2003
Last Activity: 11 March 2013, 8:46 AM EDT
Location: Ireland
Posts: 295
Thanks: 2
Thanked 1 Time in 1 Post
I did - but have not been able to figure out how to use it - can you help?
Give an example etc?
    #4  
Old 12-13-2005
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 27 July 2014, 3:08 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,121
Thanks: 43
Thanked 770 Times in 606 Posts
grep -ce "root" -e "nobody" /etc/passwd

bakunin
Sponsored Links
    #5  
Old 12-13-2005
frustrated1 frustrated1 is offline
Registered User
 
Join Date: Aug 2003
Last Activity: 11 March 2013, 8:46 AM EDT
Location: Ireland
Posts: 295
Thanks: 2
Thanked 1 Time in 1 Post
Excellent - thank you very much!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to grep pattern alok.behria UNIX for Dummies Questions & Answers 2 05-05-2011 01:34 PM
Want to grep for a pattern and display the content above that pattern ajayakunuri Shell Programming and Scripting 6 06-25-2010 06:48 AM
grep for pattern aemunathan Shell Programming and Scripting 12 05-09-2008 02:58 AM
How to grep this pattern?? askumarece Shell Programming and Scripting 13 02-20-2008 06:03 AM
help with grep the pattern bluemoon1 Shell Programming and Scripting 2 09-20-2007 11:27 AM



All times are GMT -4. The time now is 04:18 AM.