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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)'

richsarkAuthor Commented:
Hello woolmilkporc:

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

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

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

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?

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.  

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.