script to run dig using a file input


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.


Who is Participating?
woolmilkporcConnect With a Mentor Commented:

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.  
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.)
How about

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

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

richsarkAuthor Commented:
Hello woolmilkporc:

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

egrep  -i '([^\.]wan|^wan)test.txt'
richsarkAuthor Commented:
Hello Fairlight2cx:,

Do you have this script that I can test on?
egrep  -i '([^\.]wan|^wan)test.txt' output.txt
richsarkAuthor Commented:
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.