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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-18-2012
cokedude cokedude is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 6 December 2014, 7:16 PM EST
Posts: 408
Thanks: 28
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 Unix and Linux 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 Unix and Linux 01-18-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 30 March 2015, 8:53 PM EDT
Location: NM
Posts: 10,410
Thanks: 325
Thanked 854 Times in 793 Posts
awk does it with && (boolean and)

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

    #4  
Old Unix and Linux 01-20-2012
drl's Unix or Linux Image
drl drl is offline Forum Advisor  
Registered Voter
 
Join Date: Apr 2007
Last Activity: 30 March 2015, 4:32 PM EDT
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 1,758
Thanks: 56
Thanked 229 Times in 205 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 01:23 AM.