-   Programming (
-   -   sed question (

virendratp 09-10-2004 01: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.


jschiwal 09-10-2004 03: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 03:53 AM

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

Hope this helps.

virendratp 09-10-2004 04: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 12:48 PM.