Sed replace "stringvariable" with "string/variable"

时间:2015-08-07 01:44:37

标签: bash shell awk sed

I am trying to use sed in order to replace

blah.org$VARIABLE to blah.org/$VARIABLE

I can do it without using a variable with:

sed 's,orgSOMETHING,org/SOMETHING/,g' < file

but when I try

sed 's,org$VARIABLE,org/$VARIABLE/,g' < file

it doesn't work...sorry for dumb question

1 个答案:

答案 0 :(得分:1)

You need to escape the dollar symbol.

sed 's,org\$VARIABLE,org/\$VARIABLE/,g'  file

If $VARIABLE is actually a variable name then use double quotes.

sed "s,org$VARIABLE,org/$VARIABLE/,g"  file