user3777747 user3777747 - 1 year ago 113
Bash Question

How to update value of property file using sed command

I have used a variable(NEW) and assigned a required value to which property needs to be updated and then run a sed command for property (x.DB.databaseName) for file named as .


sed -i 's:^[ \t]*x.DB.databaseName[ \t]*=\([ \t]*.*\)$:x.DB.databaseName = '${NEW}':'

But it is updating -

x.DB.databaseName = k?useUnicode=x.DB.databaseName=h1amp;characterEncoding=utf-8 where h1 was the previous value assigned to that property.

Required Result-
x.DB.databaseName = K?useUnicode=true&characterEncoding=utf-8

Answer Source

It is ampersign due to which required output was not coming.

Used '\&' for &


then run above sed command.

Gives desired output

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