If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > how to use grep to search within a string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-06-04, 05:00
sachin_mt sachin_mt is offline
Registered User
 
Join Date: Jan 2003
Posts: 106
how to use grep to search within a string

Hi,

assume the shell script

a="he is fine , thank you"

i need to search for the word "fine" in this string.

How can I do that.

grep -w "fine"

how to pass the variable $a to this grep statement.
__________________
Sachi
Reply With Quote
  #2 (permalink)  
Old 04-06-04, 05:12
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
You can do :

echo $a | grep -w "fine"

If you want to store the result in a variable :

res=`echo $a | grep -w "fine"`
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On