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 > substitution in sed executed in a script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-04, 19:28
Bob Thompson Bob Thompson is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
substitution in sed executed in a script

I want to substitute the $1 parameter in a script that executes sed, but I cannot get the substitution to work. I can only get SOOOO close. Here is my script so far:

sed -e 's/foo/$1/g' <infile.nam >outfile.nam

assuming that the above command is in a script called swapme, then typing:

>swapme bar

I want every occurance of "foo" in file infile.nam changed to "bar" in file outfile.nam.

What I get is every occurance of "foo" in file infile.nam changed to "$1" in file outfile.nam. The $1 substitution does not "take" and so the literal characters $1 are what gets passed to sed. sed does what it's told to do.

What do I need to do to make the $1 get replaced with "bar"?
Reply With Quote
  #2 (permalink)  
Old 04-01-04, 01:51
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Between simple quotes, the shell doesn't substitute $1.
Tou must use double quotes.
Code:
sed -e "s/foo/$1/g" <infile.nam >outfile.nam
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-01-04, 10:09
Bob Thompson Bob Thompson is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
Excellent! If you only knew how many different things this sed/scripting novice tried! Double quotes instead of single. Woulda thought! Thanks.
-bt-
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