I put "grep multiple lines" into my favorite search engine and perused about 5 links to find
Code:
grep -oP '(?s)abc.*?def' filename
where abc is the first string to match, def is the second string to match and (?s) is the modifier that causes the dot to match eol/newline character.
so...
Code:
scasey $ cat lqtext.txt
# VLAN a
subnet 10.244.89.128 netmask 255.255.255.128 {
range 10.244.89.129 10.244.89.192;
option routers 10.244.89.254;
}
# VLAN b
subnet 10.235.4.0 netmask 255.255.254.0 {
range 10.235.4.6 10.235.4.255;
option routers 10.235.5.254;
host 7test1 {
hardware ethernet 00:00:cc:d8:1a:aa;
fixed-address 10.235.4.121;
}
host test2 {
hardware ethernet 00:00:2b:4c:ef:ab;
fixed-address 10.235.4.170;
}
}
# VLAN c
subnet 10.235.8.0 netmask 255.255.254.0 {
range 10.235.8.6 10.235.8.255;
option routers 10.235.9.254;
}
and
Code:
scasey $ grep -oP '(?s)\{.*?\}' lqtext.txt
{
range 10.244.89.129 10.244.89.192;
option routers 10.244.89.254;
}
{
range 10.235.4.6 10.235.4.255;
option routers 10.235.5.254;
host 7test1 {
hardware ethernet 00:00:cc:d8:1a:aa;
fixed-address 10.235.4.121;
}
{
hardware ethernet 00:00:2b:4c:ef:ab;
fixed-address 10.235.4.170;
}
{
range 10.235.8.6 10.235.8.255;
option routers 10.235.9.254;
}
according to man grep, the -o means Show only the part of a matching line that matches PATTERN.
without it we get:
Code:
scasey $ grep -P '(?s)\{.*?\}' lqtext.txt
subnet 10.244.89.128 netmask 255.255.255.128 {
range 10.244.89.129 10.244.89.192;
option routers 10.244.89.254;
}
subnet 10.235.4.0 netmask 255.255.254.0 {
range 10.235.4.6 10.235.4.255;
option routers 10.235.5.254;
host 7test1 {
hardware ethernet 00:00:cc:d8:1a:aa;
fixed-address 10.235.4.121;
}
host test2 {
hardware ethernet 00:00:2b:4c:ef:ab;
fixed-address 10.235.4.170;
}
subnet 10.235.8.0 netmask 255.255.254.0 {
range 10.235.8.6 10.235.8.255;
option routers 10.235.9.254;
}
The -P operator makes grep accept perl regexps
I'll leave it to you to work out how to select what you want to keep from your list of ~1000 IP addresses.
HTH