grep for 2 string with an "AND" operator | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

grep for 2 string with an "AND" operator

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-18-2012
cokedude cokedude is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 28 April 2014, 10:16 PM EDT
Posts: 396
Thanks: 26
Thanked 9 Times in 9 Posts
grep for 2 string with an "AND" operator

How can you grep for 2 string with an "AND" operator? I know you can always pipe your first grep through another grep but I was hoping there is a way to do that with an "AND" operator.
Sponsored Links
    #2  
Old 01-18-2012
venkatareddy venkatareddy is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 9 April 2012, 1:16 AM EDT
Posts: 46
Thanks: 0
Thanked 5 Times in 5 Posts
Hi,
you can use this way with egrep

egrep "word1.*word2" file

thanks,
venkat
Sponsored Links
    #3  
Old 01-18-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 2 September 2014, 4:09 PM EDT
Location: NM
Posts: 10,188
Thanks: 275
Thanked 785 Times in 734 Posts
awk does it with && (boolean and)

Code:
awk '/pattern1/ && /pattern2/' filename

    #4  
Old 01-20-2012
drl's Avatar
drl drl is offline Forum Advisor  
Registered Voter
 
Join Date: Apr 2007
Last Activity: 2 September 2014, 6:10 PM EDT
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 1,671
Thanks: 39
Thanked 193 Times in 176 Posts
Hi.

See also glark:
Quote:
A replacement for (or supplement to) the grep family, glark offers: Perl compatible regular expressions, highlighting of matches, context around matches, complex expressions (``and'' and ``or''), and automatic exclusion of non-text files.

incava.org
Some examples can be seen here with a search for glark, including an example at http://www.unix.com/shell-programmin...condition.html , post #4.

Best wishes ... cheers, drl
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
grep regex, match exact string which includes "/" anywhere on line. jelloir Shell Programming and Scripting 2 06-30-2011 12:12 AM
What "-a" operator means in "if" statement aoussenko Shell Programming and Scripting 1 03-02-2011 10:30 AM
ps -ef | grep "string1" "string2" " "string3" steve2216 Shell Programming and Scripting 11 09-03-2010 11:08 AM
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 06:41 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 12:52 AM



All times are GMT -4. The time now is 12:37 AM.