Find the answer to your Linux question:
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: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    14

    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

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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?

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    14
    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:$

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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:

    Code:
    sed "s|SAN_HOME=|$SAN_HOME_PROPERTY|g" /tmp/cfg/environment.properties.Template
    Does that work?

  6. #5
    Just Joined!
    Join Date
    Oct 2011
    Posts
    14
    Thank you, this has worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •