Perform replacement of ip address in file with variable
Hello all,
I am attempting to setup a script to change the IP address of a machine with the user specified one. I figured I could use sed to do this but so far I've been unsuccessful. Basically this is what I have:
The user sets the IP address at the beginning of the script which sets the variable.
I then want to only match IPADDR in /etc/sysconfig/network-scripts/ifcfg-eth0 and just replace the "3.3.3.3" (with the quotes) to whatever $IP is. So it would then be IPADDR="4.4.4.4" for example. I can successfully change it if I match the current IP address in the file, but I want it to work even if the IP address happens to change.
I figured you could do something like sed -i "s/^IPADDR=*.([0-9]+.[0-9]+.[0-9]+.[0-9]+)/$IP/g but that doesn't seem to be it. Any suggestions?
|