Results 1 to 5 of 5
Hi,
Please could someone advise, how can i expand a variable in SED, see my command below :
sed "s/SAN_HOME=/$TOP_HOME/g" $HOME_TOP/cfg/environment.properties.Template > $HOME_TOP/cfg/environment.properties
I get the following error :
sed: ...
- 11-01-2011 #1Just Joined!
- Join Date
- Oct 2011
- Posts
- 12
expand variable in SED
Hi,
Please could someone advise, how can i expand a variable in SED, see my command below :
sed "s/SAN_HOME=/$TOP_HOME/g" $HOME_TOP/cfg/environment.properties.Template > $HOME_TOP/cfg/environment.properties
I get the following error :
sed: -e expression #1, char 23: unknown option to `s'
thank you
- 11-01-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
You just need to use double quotes to have sed recognize variables, and you've done that (at least in the command you posted). Your command worked for me. Did you cut-and-paste it exactly as you ran it on your system?
- 11-01-2011 #3Just Joined!
- Join Date
- Oct 2011
- Posts
- 12
Hi,
this is the exact commands I'm using, see below, as I'm still geeting the SED error -Please could you advise what I'm doing wrong :
[dev@dev06agorel cfg] DEV6:$
[dev@dev06agorel cfg] DEV6:$
[dev@dev06agorel cfg] DEV6:$ SAN_HOME_PROPERTY=`cat $BKUPDIR/environment.properties | grep SAN_HOME=`
[dev@dev06agorel cfg] DEV6:$
[dev@dev06agorel cfg] DEV6:$ echo "$SAN_HOME_PROPERTY"
SAN_HOME=/san/dev6/bin/REL1_AO471_ARA254
[dev@dev06agorel cfg] DEV6:$
[dev@dev06agorel cfg] DEV6:$ cat $TOP/cfg/environment.properties.template | grep SAN_HOME=
SAN_HOME=
[dev@dev06agorel cfg] DEV6:$
[dev@dev06agorel cfg] DEV6:$ sed "s/SAN_HOME=/$SAN_HOME_PROPERTY/g" $TOP/cfg/environment.properties.template
sed: -e expression #1, char 23: unknown option to `s'
[dev@dev06agorel cfg] DEV6:$
- 11-01-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
Ah, you have forward slashes in the value of your variable. But the forward slash is also being used as your separator character in sed. Try this:
Does that work?Code:sed "s|SAN_HOME=|$SAN_HOME_PROPERTY|g" /tmp/cfg/environment.properties.Template
- 11-01-2011 #5Just Joined!
- Join Date
- Oct 2011
- Posts
- 12
Thank you, this has worked.


Reply With Quote