I have an input file that's missing some data. I need to figure out how to only print the server name if there is no nameserver data.
server1.mydomain.com
search somdomain.com
nameserver 10.1.1.154
nameserver 10.1.1.155
server2.mydomain.com
server3.mydomain.com
server4.mydomain.com
; generated by /sbin/dhclient-script
search mydomain.com
nameserver 10.1.1.155
nameserver 10.1.1.154
My awk script so far looks like this:
/\.com/ && $0 !~ /search /{server = $1; getline; if ($0 !~ /[a-z]/) nameserver = ""}
/^nameserver/{if (NF) nameserver[++nrc] = $2}
/^$/{for (i=1;i<=nrc;i++) printf ("%-40s %-18s\n", server, nameserver)}
My desired output is:
server1.mydomain.com 10.1.1.154 10.1.1.155
server2.mydomain.com
server3.mydomain.com
server4.mydomain.com 10.1.1.154 10.1.1.155
There will be times when there are more than 2 different nameservers.
Any help would be greatly appreciated.
Thanks,
John
server1.mydomain.com
search somdomain.com
nameserver 10.1.1.154
nameserver 10.1.1.155
server2.mydomain.com
server3.mydomain.com
server4.mydomain.com
; generated by /sbin/dhclient-script
search mydomain.com
nameserver 10.1.1.155
nameserver 10.1.1.154
My awk script so far looks like this:
/\.com/ && $0 !~ /search /{server = $1; getline; if ($0 !~ /[a-z]/) nameserver = ""}
/^nameserver/{if (NF) nameserver[++nrc] = $2}
/^$/{for (i=1;i<=nrc;i++) printf ("%-40s %-18s\n", server, nameserver)}
My desired output is:
server1.mydomain.com 10.1.1.154 10.1.1.155
server2.mydomain.com
server3.mydomain.com
server4.mydomain.com 10.1.1.154 10.1.1.155
There will be times when there are more than 2 different nameservers.
Any help would be greatly appreciated.
Thanks,
John