LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-09-2009, 01:01 AM   #1
amit_pansuria
Member
 
Registered: Sep 2006
Posts: 73

Rep: Reputation: 15
how to do Logical AND with grep or egrep


Hello,

I want to perform logical AND with grep or egrep
. I have one file which contains number of different names.

Now I want to check some names among them exist.

so how do I perform this operation with grep or egrep

Regards,
Amit
 
Old 08-09-2009, 01:06 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Generally, I would pass the results from grep to another grep statement.

Code:
grep condition1 file|grep condition2
 
Old 08-09-2009, 02:39 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
using awk
Code:
awk '/condition1/ && /condition2/' file
using egrep
Code:
egrep "condition1.*condition2|condition2.*condition1" file
using grep
Code:
grep -E "condition1.*condition2|condition2.*condition1" file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep/egrep logical AND function? boozer_2 Linux - Newbie 11 04-10-2010 01:19 AM
Help with ls and grep/egrep kasthana Linux - Newbie 1 05-29-2008 01:06 PM
using grep and egrep in the terminal KumARan23 Linux - Newbie 3 11-11-2007 09:27 AM
egrep/grep regex question buldir Programming 7 05-08-2006 07:17 PM
Using Grep and Egrep linux-nerd Linux - General 5 10-10-2004 11:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration