Replacement of text in a file

Hi ,

I have some data in my file(properties.txt) like this.

# agent.properties
agent.dmp.Location=
agent.name=

I need to relpace the
agent.dmp.location with agent.dmp.Location = /opt/VRTS/vxvm

I am using the follwing to replace the string

AGENT_NAME=snmp
AGENT_DMP_LOCATION=/var/opt
sed "s/agent.name=.*/agent.name= $AGENT_NAME/g" properties.txt > properties.txt.tmp;
mv properties.txt.tmp properties.txt > /dev/null 2>&1

the above command is successfully executing and the value in the file is

# agent.properties
agent.dmp.Location=snmp
agent.name=

but for agent.dmp.Location

sed "s/agent.dmp.Location=.*/agent.dmp.Location= $AGENT_DMP_LOCATION/g" properties.txt > properties.txt.tmp;
mv properties.txt.tmp properties.txt > /dev/null 2>&1

is showing error like this

sed: command garbled: s/agent.dmp.Location =.*/agent.dmp.Location= /var/opt/g

i think the problem is due the variable AGENT_DMP_LOCATION=/var/opt..since it has '/' .

could anyone please solve this issue.
thanks in advance.

That's because the shell sees your command as

sed "s/agent.dmp.Location=.*/agent.dmp.Location= /var/opt/g" properties.txt > properties.txt.tmp;

which is incorrect. Try writing your sed command as

sed "s|agent.dmp.Location=.*|agent.dmp.Location= $AGENT_DMP_LOCATION|g" properties.txt > properties.txt.tmp;

Thanks Mr. Genius

It worked fine.