script to run dig using a file input

Posted on 2011-02-20
Last Modified: 2012-05-11

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.


Question by:richsark
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Expert Comment

ID: 34940939
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.)
LVL 68

Expert Comment

ID: 34941129
How about

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


Author Comment

ID: 34942934
Hello woolmilkporc:

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

egrep  -i '([^\.]wan|^wan)test.txt'
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 34942944
Hello Fairlight2cx:,

Do you have this script that I can test on?
LVL 68

Expert Comment

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

Author Comment

ID: 34943192
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?
LVL 68

Accepted Solution

woolmilkporc earned 500 total points
ID: 34943268

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.  

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl getopt long help 34 116
how to pick specific file from ftp 13 76
Use Perl to Remove Large Quantity of Files Quickly 8 28
need a help to fix one if else shell script issue 6 33
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question