I want to extract the lines in a file containing the range for particular subnet
Input:
subnet 172.16.31.0 netmask 255.255.255.0 {
# default gateway
option routers 172.16.31.10;
option subnet-mask 255.255.255.0;
option domain-name "aaaaaa";
option domain-name-servers 172.16.31.10;
#option nis-domain "domain.org";
range dynamic-bootp 172.16.31.80 172.16.31.90;
default-lease-time 21600;
max-lease-time 43200;
host test {
hardware ethernet 00:23:8b:42:3f:d1;
fixed-address 172.16.31.3;
}
}
subnet 172.16.31.1 netmask 255.255.255.0 {
# default gateway
option routers 172.16.31.11;
option subnet-mask 255.255.255.0;
option domain-name "aaaaaa";
option domain-name-servers 172.16.31.11;
#option nis-domain "domain.org";
range dynamic-bootp 172.16.31.80 172.16.31.90;
default-lease-time 21600;
max-lease-time 43200;
host test {
hardware ethernet 00:23:8b:42:3f:d8;
fixed-address 172.16.31.4;
}
}
I want to extract range dynamic-bootp for subnet 172.16.31.0.
Expected output:
range dynamic-bootp 172.16.31.80 172.16.31.90;
Is there any sed solution?
Update: Structure of the content will not be same, lines may get added / deleted based on config requirement
Tried -
sed -n '/^subnet 10.172.31.0 netmask/,/^}/{'
-n ' s/^\( *range dynamic-bootp\)./,/^}'
-n '}'
file