Ricky Ricky - 8 months ago 52
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


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.