The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Logical Servers iBot HP Server News and Podcasts RSS 0 09-09-2008 12:08 PM
logical OR in sed anchal_khare Shell Programming and Scripting 8 02-08-2008 03:38 AM
Logical OR using sed thejasviv Shell Programming and Scripting 0 09-12-2007 09:29 PM
logical if condition nano2 Shell Programming and Scripting 7 06-27-2007 12:24 PM
AIC logical volumes 98_1LE UNIX for Dummies Questions & Answers 1 09-14-2002 10:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2008
Needhelp2 Needhelp2 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 29
How to do logical AND and logical OR with grep

Hi can someone please help me on this.

I need to perform this code:


Grep any lines that meets the following criteria

(A AND B) OR (A AND C)



I tried this code, but it didn’t work


Grep-I "A &&B" | "A&&C" *.* [~/foldername]$


thanks in advance
  #2 (permalink)  
Old 09-20-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,400
you want this..
Quote:
grep 'A' filename|grep 'B' || grep 'A' filename |grep 'C'
or... this..
Quote:
grep 'A' filename|grep 'B' &&grep 'A' filename |grep 'C'
  #3 (permalink)  
Old 09-20-2008
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 426
here is an alternate way to do it with awk.

Code:
awk '/A/ && /B/ || /A/ && /C/' filename
  #4 (permalink)  
Old 09-20-2008
yahyaaa's Avatar
yahyaaa yahyaaa is offline
Registered User
  
 

Join Date: May 2008
Location: Jordan
Posts: 89
try this also ...

egrep '(A)(B|C)' input_file

Regards
  #5 (permalink)  
Old 09-20-2008
Needhelp2 Needhelp2 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 29
thanks , but egrep didnt work for me

error message " egrep is not recognized as an internal or external command"

could this be , due to cygwin??
  #6 (permalink)  
Old 09-20-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,400
Quote:
Originally Posted by Needhelp2 View Post
thanks , but egrep didnt work for me

error message " egrep is not recognized as an internal or external command"

could this be , due to cygwin??
ya i think in cygwin only simple grep works.....
  #7 (permalink)  
Old 09-20-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,319
The awk solution should work, try to place the and statements between parenthesis:

Code:
awk '(/A/ && /B/) || (/A/ && /C/)' filename
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0