using a dig
command in a shell script and want to output into csv format flags and authority section
dig @ns1.hosangit.com djzah.com +noall +authority +comments
output
; <<>> DiG 9.8.3-P1 <<>> @ns1.hosangit.com djzah.com +noall +authority +comments
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64505
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; AUTHORITY SECTION:
djzah.com. 3600 IN NS ns3.eventguyz.com.
djzah.com. 3600 IN NS ns1.eventguyz.com.
djzah.com. 3600 IN NS ns2.eventguyz.com.
Expected output for csv is ( domain
, flags
(not always these three), authority section
(could be 5) ):
djzah.com,qr,aa,rd,ns3.eventguyz.com,ns1.eventguyz.com,ns2.eventguyz.com
I was trying to use awk
and/or sed
but am having difficulty searching for a pattern like for the flags section
;; flags: (then use a space delimiter until you reach ;)
Then the Authority section, I assume you would search for ;; AUTHORITY SECTION: Then create an array and only use the last.
I don't know what I'm doing.