The only difference between the 2 code variants is that I replaced the two grep's with an awk, and the awk also prints columns 1 and 5 rather than the whole line.
Thus something that looks like
Code:
example.com 86400 IN NS name.server.example.com
should output
Code:
example.com name.server.example.com
I had tested it on my CentOS 5 machine and it worked fine.
Thinking about it, though, we can somplify even more; the awk part could be
Code:
awk '$1 !~ /^;/ && $4 == "NS" { print $1,$5}'And, of course, the dig output doesn't have $4=NS on the comment lines, so it's even simpler as
Code:
awk '$4 == "NS" { print $1,$5}'This makes the whole loop:
Code:
while read i
do
dig $i ns
done < domains_list.txt | awk '$4 == "NS" {print $1,$5}' > output.txt
Example results:
Code:
% cat domains_list.txt
google.com
facebook.com
% while read i
do
dig $i ns
done < domains_list.txt | awk '$4 == "NS" {print $1,$5}'
google.com. ns1.google.com.
google.com. ns2.google.com.
google.com. ns3.google.com.
google.com. ns4.google.com.
facebook.com. ns3.facebook.com.
facebook.com. ns4.facebook.com.
facebook.com. ns5.facebook.com.
facebook.com. ns1.facebook.com.
facebook.com. ns2.facebook.com.