LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-14-2009, 12:14 PM   #1
ahmedb72
Member
 
Registered: Jan 2006
Location: Sydney
Distribution: RHEL
Posts: 72

Rep: Reputation: 15
logical operators in grep


Hi,
How can I implement logical operators in grep? I checked the man info and couldn't figure it out.

For example, I'd like to display lines in file1.txt that contains word1 OR word2.

cat file1.txt | grep word1 OR word2

Thanks in advance.
 
Old 12-14-2009, 01:30 PM   #2
SethsdadtheLinuxer
Member
 
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
try the --regexp flag.
 
Old 12-14-2009, 01:43 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,966
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
grep -E "word1|word2" file1.txt

No need to swing cats =}
 
1 members found this post helpful.
Old 12-14-2009, 07:55 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
another tool you can use is awk,
ORing
Code:
awk '/WORD1|WORD2/' file
ANDing
Code:
awk '/WORD1/&&/WORD2/' file
 
1 members found this post helpful.
  


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
how to do Logical AND with grep or egrep amit_pansuria Programming 2 08-09-2009 02:39 AM
Extending logical volume LogVol01 Insufficient allocatable logical exte swap space umeshsharma Linux - Newbie 4 06-22-2009 12:26 PM
PHP5: Logical Operators vs. If-Else unreal128 Programming 2 11-15-2006 10:52 PM
? on logical operators in BASH eroica Linux - Software 10 02-01-2005 01:12 PM


All times are GMT -5. The time now is 06:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration