script to run dig using a file input

richsark used Ask the Experts™

I am using dig -f ( -f means a file name) which I have a list if zones. like

It runs fine but I only want to know if a certain NS record exists. For example if that criteria matches create a file with the domain name and NS record.

If is not part of the NS record then output a file with the zone name and the NS record


Zone name:                        NS Record                                                    

Report 2

All zones that have are:

is there a grep or sed command to go through the file to show me?

I tried grep -i output.txt

I get a response 3 times for each zone meaning duplicates cause there are,, and for each zone name

Each domain has these 3 entries, I just want to know per domain. I dont want to end up with a report that has 3 same domains for each NS record.


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I'd do it in perl and every time I found an NS record that matched the selection criterion, I'd store the results in an array.  Then just spit out the array for the report section.

If the report had to handle multiple criterion, I'd use a hash with each match criterion as the key for the hash, and push onto an array the values for those keys.  (Hash of arrays.)
Most Valuable Expert 2013
Top Expert 2013

How about

egrep  -i '([^\.]wan|^wan)'



Hello woolmilkporc:

Its not working. I am not sure how to run it.

egrep  -i '([^\.]wan|^wan)test.txt'
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.


Hello Fairlight2cx:,

Do you have this script that I can test on?
Most Valuable Expert 2013
Top Expert 2013

egrep  -i '([^\.]wan|^wan)test.txt' output.txt


Hi woolmilkporc:

Well, I must be a dunce, i did egrep  -i '([^\.]wan|^wan)test.txt' output.txt

may I know what is test.txt?
output.txt contains the data I want to grep on right?
Most Valuable Expert 2013
Top Expert 2013

I inadvertently copied the line from your comment and overlooked your test.txt. You put it there, so I don't know what it is.

egrep  -i '([^\.]wan|^wan)' output.txt

Yes, "output.txt contains the data I want to grep on".

The statement does nothing else than grepping for "" without the dot "." in front, so "" or the like will not be found.
The string following the pipe "|" takes care to find "" at the start of a line as well.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial