SED replacement of placeholders

Hi All,

I am facing a problem while using SED in Linux.

I have a property file which contains a string

local.mds.dir=${basedir}/deployComposites

It has be to replaced with another string, and value of that string should be initialized at runtime. So I use placeholder there. My substituted string should look like

local.mds.dir=${WORKSPACE}/${TAG_DIR}/mds

where

WORKSPACE=/usr/hudson/.hudson/jobs/temp/workspace
TAG_DIR=1.1.2

So after substitution it should look like

local.mds.dir=/usr/hudson/.hudson/jobs/temp/workspace/1.1.2/mds

I am using sed command

sed 's/local.mds.dir=${basedir}\/deployComposites/local.mds.dir=${WORKSPACE}\/${TAG_DIR}\/mds/g' ${PROPERTIES_FILE}

But only placeholder is coming there, not the values are populated. After running the SED it apprears

local.mds.dir=${WORKSPACE}/${TAG_DIR}/mds

it seems sed is not getting the values
Any ideas where I am going wrong? I am happy to use any other substitution commands as well

Thanks in advance,
Bhaskar

use double quotes for expand the your variables..

# sed "s|local.mds.dir=\${basedir}/deployComposites|local.mds.dir=$WORKSPACE/$TAG_DIR/mds|" ${PROPERTIES_FILE}
2 Likes

Thanks a lot. It worked.

Cheers,
Bhaskar