I'm trying to write to an auto-generated
/etc/network/interfaces file of a newely provisioned XEN Ubuntu (12.04/10.04/8.04) DomU server at boot time using (currently)
The auto-generated file is formatted as below:
auto eth0 iface eth0 inet static address 192.168.0.88 gateway 192.168.0.254 network 255.255.255.255 auto lo iface lo inet loopback
sed, I'm trying to alter lines 1 & 2, add a third line, remove the gateway and last two lines, and add four extra lines at the end.
I'm currently stuck on adding the third line, as the script adds this line everytime it's run:
#!/bin/bash sed -i "1s/.*/auto lo eth0/" /tmp/interfaces sed -i "2s/.*/iface lo inet loopback/" /tmp/interfaces sed -i "2a\iface eth0 inet static" /tmp/interfaces
Is it possible to add the third line only if it doesn't exist using
Likewise, how can I delete the gateway and last two lines only if they don't exist?
I'm new to
sed, so am wondering whether I should be looking at
awk instead for achieving this?
Any help would be greatly appreciated.
EDIT: Just realised I should really ask this question over at StackOverflow