LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed question (https://www.linuxquestions.org/questions/programming-9/sed-question-228827/)

virendratp 09-10-2004 12:26 AM

sed question
 
Hi all,
I am facing a problem with sed. I want to replace a constant string with an environment variable $BASEDIR.
I tried
sed -e "s/this/$BASEDIR/g" temp.txt
sed -e 's/this/'"$BASEDIR"'/g' temp.txt

but it gives me an error
sed: -e expression #1, char 13: Unknown option to `s
for both the cases.

Any help would be appreciated.

Thanks.

jschiwal 09-10-2004 02:50 AM

The problem is due to the variable containing a forward slash, which is what you are using a a separator in the sed command. Try this instead:
sed -e 's#this#'"$BASEDIR"'#g' temp.txt

druuna 09-10-2004 02:53 AM

Please use the search function this forum provides before posting, I answered this question twice in the last 48 hours......

http://www.linuxquestions.org/questi...hreadid=227588
http://www.linuxquestions.org/questi...hreadid=228454

Hope this helps.

virendratp 09-10-2004 03:21 AM

it works jschiwa.
I did try to search but couldnt relate the things that were there to my problem so this post.

Thanks for the replies.


All times are GMT -5. The time now is 11:14 AM.