Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-18-2005, 01:20 AM   #1
LQ Newbie
Registered: Mar 2005
Posts: 8

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

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
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
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
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.


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 7 12-19-2015 01:03 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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 AM.

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