LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 11-20-2006, 11:54 PM   #1
Fond_of_Opensource
Member
 
Registered: May 2006
Posts: 55

Rep: Reputation: 15
string comparision


Hi friends,

I have a string variable in shell script as :

echo $str
-------------------
Five-time Olympic champion Ian Thorpe retired from competitive swimming on Tuesday at the age of 24, saying breaking records had lost its allure.



---------------

Now I want to check whether the word "from" (case insensitive) exists or not in the above string variable $str. I want to get TRUE or FALSE condition checking.

How to do it in shell script?

Last edited by Fond_of_Opensource; 11-21-2006 at 01:45 AM.
 
Old 11-21-2006, 03:47 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
echo $str|grep -i from >/dev/null 2>&1
and check $? afterwards ... 0 is true, 1 is false.


Cheers,
Tink
 
Old 11-21-2006, 04:02 AM   #3
bikecheng
LQ Newbie
 
Registered: Aug 2006
Location: Beijing China
Distribution: RedFlag
Posts: 6

Rep: Reputation: 0
using this may be better: echo $test|grep -iE '\<from\>'
 
  


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
9.0 - 10.1 official comparision Nau Mandriva 1 04-11-2005 10:08 AM
comparision Ammad Linux - Networking 1 03-10-2005 06:26 AM
A picture comparision program? vmicho Linux - Software 3 10-27-2004 01:47 PM
Proper GLX Gears Comparision otchie1 Linux - Hardware 9 10-08-2004 08:46 AM
string comparision in linux scripts rm1 Programming 7 09-20-2004 12:25 PM


All times are GMT -5. The time now is 04:13 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