Arun
Arun

Reputation: 1220

How to use dig command of bulk/batch lookups to read hostnames from a text file?

I have a text file with 1.txt with the following set of domains

adrive.com
amazon.com
amazon.ca
amazon.cn
amazon.co.jp
amazon.co.uk
amazon.com.au
amazon.com.br
amazon.com.mx
amazon.de
amazon.es
amazon.fr
amazon.in
amazon.it
console.aws.amazon.com

I did the following command to get the TXT record of a domain

dig TXT 1.txt 

I am not sure,How to do this ?

Upvotes: 3

Views: 8920

Answers (1)

aveuiller
aveuiller

Reputation: 1551

If you want to call dig TXT on each record of your file, you may want to use this command:

 cat 1.txt | xargs dig TXT

As stated in the xargs man:

xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command.

Edit: I just saw that dig does have a -f option, so you can also use:

dig TXT -f 1.txt

The output of the two commands are the same.

Upvotes: 5

Related Questions