Portál AbcLinuxu, 12. května 2025 06:00
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet static address 192.168.200.4 netmask 255.255.255.0 network 192.168.200.0 broadcast 192.168.200.255 gateway 192.168.200.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 192.168.200.1 #dns-search # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). allow-hotplug eth1 iface eth1 inet static address 192.168.300.4 netmask 255.255.255.0 network 192.168.300.0 broadcast 192.168.300.255 gateway 192.168.300.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 192.168.200.1 #dns-searchPotrebujem operovať vždy z konkrétnym rozhraním. Rozmýšľal som hľadať IP jedným regexpom medzi regexpami s "allow-hotplug $rozhranie", a prvým nasledujúcim výskytom regexpu "dns-search". Je to vôbec možné len s pomocou coreutils, alebo treba aj awk. Ešte som s regexpami nerobil a neviem či na toto coreutils stačia.
grep -A 9 '^allow-hotplug eth0$'
Rozmýšľal som hľadať IP jedným regexpom medzi regexpami s "allow-hotplug $rozhranie", a prvým nasledujúcim výskytom regexpu "dns-search".
To jde i primo v sedu: sed -e '/allow-hotplug eth0/,/dns-search/s/old_ip/new_ip/'
sed "/regexp/,+2 s/co nahradit/cim nahradit/"Napr:
printf "a\nb\nc\nd\ne\n" | sed "/b/,+2 s/.*/X/" a X X X e
$ ed /etc/network/interfaces EOF /^iface eth1 inet static +1,/^$/d i address 1.2.3.4 netmask 255.255.0.0 gateway 2.4.5.6 . w q EOF(pred prvnim EOF maji byt samozrejme dve spicate zavorky ukazujici doleva, ale foru se to zrovna moc nelibi)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.