LinuxQuestions.org
Visit Jeremy's Blog.
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 04-18-2005, 01:20 AM   #1
sumitarun
LQ Newbie
 
Registered: Mar 2005
Posts: 8

Rep: Reputation: 0
Question How to use "OR" option in a grep command.


Hi,
i want t write a grep command that will search for a string called say , 'False' in the sentence and will do some activites if that string is present.. but if there is another strin say True' is present in that string then do something else...

at the same time both 'False'and 'True' strings will not be present in the sentence.
So how to use a single grep command and look for the strings "False" or "True"
 
Old 04-18-2005, 01:29 AM   #2
marghorp
Senior Member
 
Registered: Jan 2004
Location: Slovenia
Distribution: Slackware 10.1, SLAX to the MAX :)
Posts: 1,040

Rep: Reputation: 45
You are not looking for OR, you are looking for IF. This depends on what programming language you use. You will determine if FALSE is true, by running a grep false on some string. See the man grep pages to see what signal the grep command returns upon it's execution. It should probably return 0 on a clear run (the string is found) and 1 or -1 on a false run (the string is not found). But see the man pages anyway to clarify this.
 
Old 04-18-2005, 01:39 AM   #3
sumitarun
LQ Newbie
 
Registered: Mar 2005
Posts: 8

Original Poster
Rep: Reputation: 0
Actually my fault... well iam looking for "OR" condition. If in a string is is either "False " or "True" word present then a particular action is supposed to take place. so iam looking for any of the two string present in a single sentence. But then at a particular time only one of the two string will be present in the sent. Sorry for the wrong information
 
Old 04-18-2005, 01:44 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Either awk or a script may be better suited for what you want to do. If you want to do something like filter lines with yes in one file and line with no in another, then the program sed would suffice. Awk would be better if your file is organized into columns and fields.

As an answer to your question however, you can check for more then one pattern like this:
grep -e pattern1 -e pattern2 ...

I will sometimes use grep to filter out the very long results of the locate command.
grep -v -e pattern1 -e pattern2 ...
I would add a new pattern that I'm not interested in until the listing is small enough to find the pattern I'm looking for. By the way, the -v option inverts the result of grep and eliminates patterns with the line.
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 10:35 AM
"grep" Command (SystemV/68 system) xtremexp Other *NIX 3 05-28-2005 07:25 PM
rpm -bp command not working says "-bp: unknown option" Niceman2005 Linux - Software 2 11-08-2004 01:36 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
anging "Protocol" option to "IMPS/2" in XF86Config-4 causes problems zstingx Linux - General 2 10-27-2003 09:47 AM


All times are GMT -5. The time now is 03:49 AM.

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