1

I am using DIG command in linux and getting results i want but how can i get output results written in CSV file and get them saved ?

Current output is below which i want in csv file :

inspectieSZW.nl.        19      IN      A       178.22.85.166
inspectieSZW.nl.        19      IN      A       178.22.85.169
belgique.be.            6940    IN      A       193.191.245.244
belgie.be.              6940    IN      A       193.191.245.244
christiemorreale.be.    3340    IN      A       128.65.195.89
regards.fr.             340     IN      A       137.74.167.22
dragons.jp.             19      IN      A       52.198.194.108
dragons.jp.             19      IN      A       18.182.191.127
j-sm.jp.                79      IN      A       49.212.243.98
ndenter.co.kr.          3341    IN      A       223.26.138.51
semillasdelfuturo.com.co. 341   IN      A       50.62.88.87
redesdamare.org.br.     3342    IN      A       149.56.157.48

2 Answers 2

2

Enter every dig command like this (replace [HOSTNAME] by the host name you want to DIG):

dig [HOSTNAME] | grep IN | grep -v ";" | tr -s "[:blank:]" "," >> savedoutput.csv
  1. The first grep leaves only the lines containing "IN".
  2. The second grep removes the line starting with ; in the QUESTION SECTION.
  3. The tr command replaces all spaces by commas.
  4. The >> appends all output to the file called savedoutput.csv.
3
  • Thanks , that worked like a charm . I am using big list of domains and there are several domains where are no NS results for domains and DIG is skipping domains with no results hence not writing or mentioning them in output file , is there anyway i can get those domains with no NS results also written in output file ?
    – Kay Tee
    Apr 28, 2020 at 18:04
  • please help , i am noob in linux and just followed a tutorial and stuck here
    – Kay Tee
    Apr 29, 2020 at 7:14
  • 1
    That is a different question, and also more complicated than the normal case. Please post a new question with this problem; the friendly people here will probably help you with a script that takes the hostname as a parameter and outputs a line if no NS results are found.
    – Jos
    Apr 29, 2020 at 7:26
1

Converting output from dig to csv format using sed.

$ sed <(dig askubuntu.com) > out.csv \
  -nE -e '/^[^;].*IN/{s/[[:blank:]]+/,/g;p}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .