Ricky Ricky - 1 year ago 80
Bash Question

how to replace $ value in a file using sed command?

I am using below command to replace some values in a file. But its not get replaced even though the command is running fine.

sed -i 's|"TIBEMS:U1278:${Internal.Agent Name}"|"TIBEMS:U1278:${External.Agent Name}"|g' EMS_PRIMS01_7111_Monitor.hrb

Answer Source

You need to escape the meta-characters

 sed -i "s|\"TIBEMS:U1278:\${Internal.Agent Name}\"|\"TIBEMS:U1278:\${External.Agent Name}\"|g" EMS_PRIMS01_7111_Monitor.hrb 
 #      ^^             ^^                     ^^ ^^               ^^                       ^^
 #  Notice the escaping done for all the meta-characters i.e. '"' and '$'

With this your in-place replacement will work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download