LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-07-2008, 02:09 AM   #1
CheeSen
LQ Newbie
 
Registered: Sep 2008
Posts: 14

Rep: Reputation: Disabled
Bash Shell


how to match a keyword to search into the text txt.
Example :

i enter a keyword "GO"
then system return keyword not found in text.txt
if i enter keyword "PLAY" which has in text.txt
then it will show
PLAY on the screen

how to do that ? using sed? awk ?

Last edited by CheeSen; 09-07-2008 at 02:26 AM.
 
Old 09-07-2008, 02:15 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I suppose a simple way would be to use grep and then test the return value (which is stored in $? and is 1 if the string isn't found and 0 if it is). This may not be the best way, but it's one way to do it.

Edit: also, you really could have used a more descriptive thread title.

Last edited by Nylex; 09-07-2008 at 02:20 AM.
 
Old 09-07-2008, 02:33 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Actually, I just looked at the Advanced Bash-Scripting Guide page on Test Constructs and you don't need to explicitly use $?, because Bash checks it automatically when you do "if command ...".
 
  


Reply



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
copy directories and files recursively using C shell or bash shell bostonuser Programming 7 06-06-2008 01:24 AM
own shell in place of bash shell somu_thedev Programming 6 07-31-2007 10:13 AM
Run a C Shell using only Bash shell HSN Linux - Software 1 12-25-2006 07:44 AM
Bash shell triplem Linux - Software 1 04-14-2003 08:01 AM
Help!!!!! Bash Shell???? DarkHorse Linux - Newbie 7 06-04-2001 12:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration