'sed' : How to add new line after string match + 2 lines -
i add new line after string match + 2 lines.
here file :
allow-hotplug eth0 auto eth0 iface eth0 inet static address 172.16.2.245 netmask 255.255.254.0 gateway 192.168.1.1 allow-hotplug eth1 #auto eth1 iface eth1 inet static address 192.168.0.240 netmask 255.255.255.0 iface eth2 inet static address 192.168.2.240 netmask 255.255.255.0
i want add 'gateway 192.168.1.1' after found 'iface eth1' + 2 lines.
example: need after execute sed command
allow-hotplug eth0 auto eth0 iface eth0 inet static address 172.16.2.245 netmask 255.255.254.0 gateway 172.16.2.254 allow-hotplug eth1 #auto eth1 iface eth1 inet static address 192.168.0.240 netmask 255.255.255.0 gateway 192.168.1.1 iface eth2 inet static address 192.168.2.240 netmask 255.255.255.0
i know how find , move 2 lines after, append line after specific string, etc. not combine 2 operation. steph
this seems work:
sed '/^iface eth1/{n;n;s/$/\ngateway 192.168.1.1/}' input.txt
add -i
option sed
save result input.txt
.