Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    expand variable in SED


    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/ > $HOME_TOP/cfg/

    I get the following error :

    sed: -e expression #1, char 23: unknown option to `s'

    thank you

  2. #2
    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

    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/ | grep SAN_HOME=`
    [dev@dev06agorel cfg] DEV6:$
    [dev@dev06agorel cfg] DEV6:$ echo "$SAN_HOME_PROPERTY"
    [dev@dev06agorel cfg] DEV6:$
    [dev@dev06agorel cfg] DEV6:$ cat $TOP/cfg/ | grep SAN_HOME=
    [dev@dev06agorel cfg] DEV6:$
    [dev@dev06agorel cfg] DEV6:$ sed "s/SAN_HOME=/$SAN_HOME_PROPERTY/g" $TOP/cfg/
    sed: -e expression #1, char 23: unknown option to `s'
    [dev@dev06agorel cfg] DEV6:$

  4. $spacer_open
  5. #4
    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:

    sed "s|SAN_HOME=|$SAN_HOME_PROPERTY|g" /tmp/cfg/
    Does that work?

  6. #5
    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