How can I replace caracters “on the fly” when using sed ?
Example :
I want this command to be executed :
/bin/sed ‘s/HOSTNAME=.*/HOSTNAME=server_domain_com/g’ /etc/sysconfig/network
Instead of this one :
/bin/sed ‘s/HOSTNAME=.*/HOSTNAME=server.domain.com/g’ /etc/sysconfig/network
the string “server.domain.com” is contained in a env variable and I would like to replace the dots by an underscore before replacing the appropriate line in /etc/sysconfig/network.
Thank you!
You can do this with bash substitution too:
The
//instructs it to change all occurences (like g in sed). Do not forget the-iflag to actually change the file, not just print it.