Search code examples
linuxbashdig

Adding filename/domain name before result of cat


When i run below command I got result like

dig +short ns kinoafisha.info | awk -v RS='' '{gsub("\n", ", "); print}' >> test.csv
dig +short ns linux.com | awk -v RS='' '{gsub("\n", ", "); print}' >> test.csv

Result

ns2.kinoafisha.info., ns1.kinoafisha.info.
ns1.dnsimple.com., ns2.dnsimple.com., ns3.dnsimple.com., ns4.dnsimple.com.

(my question) I am trying like (1st domain name and then the DNS)

kinoafisha.info, ns2.kinoafisha.info., ns1.kinoafisha.info.
linux.com, ns1.dnsimple.com., ns2.dnsimple.com., ns3.dnsimple.com., ns4.dnsimple.com.

PS: I will all domains in a loop (CSV) and then run command like

Loop

while IFS= read -r line
do
   dig +short ns $line | awk -v RS='' '{gsub("\n", ", "); print}' >> test.csv

done < domains.txt

I need to run multiple commands for 100 domains like dig +short ns and dig +short a and dig +short mx and so on... I want to print result horizontal. please suggest.

i try

   dig +short ns $line | awk -v RS='' '{gsub("\n", ", "); print $line,$0}' >> test.csv

but didnt work


Solution

  • Using echo to concatenate line value and your dig command output:

    echo "$line ,"  $(dig +short ns $line | awk -v RS='' '{gsub("\n", ", "); print $0}') >> test.csv