dig: Machine friendly output expected (tabs, spaces, etc)
Summary
dig
is not consistent with the use of tabs and spaces in output, which is confusing per the the man
-page itself (for the +[no]multiline
-option):
The default is to print each record on a single line to facilitate machine parsing of the dig output.
This should, in my interpretation, mean that the intention is for dig
to produce machine friendly output by default. Therefore this is filed as a bug
rather than a feature request. However, I realize the hassle of of changing the default output format since most often it is possible to work around it, and most users, I assume, have not encountered it. I encountered it when going through entire zones-files by AXFR when I realized that some outputs were a bit off after doing some yoga on the zone-contents.
BIND version used
BIND 9.16.12 (Stable Release) <id:aeb943d>
Steps to reproduce
Illustration (using one long domain name and one short domain name which causes the issue):
> dig +noall +answer ns iis.se abbekaslagerologistik.se | cut -f1,4,5
iis.se. 3417 IN
iis.se. 3417 IN
iis.se. 3417 IN
abbekaslagerologistik.se. 118 ns1.teleservice.net.
abbekaslagerologistik.se. 118 ns2.teleservice.net.
I get different fields depending on how many tabs and spaces dig
chooses to use for that particular record. I would expect that "machine friendly" output would be in line with POSIX command behavior.
Also note above that field1
is iis.se
and abbekaslagerologistik.se. 118
(since there is a space here, not a tab). And that the abbekaslagerologistik.se.
lack a field3
.
What is the current bug behavior?
Using alias defined at https://superuser.com/a/1503113/ in below examples.
alias whitespace="sed 's/ /·/g;s/\t/→/g;s/\r/§/g;s/$/¶/g'"
For example:
> dig +noall +answer ns iis.se abbekaslagerologistik.se
iis.se. 358 IN NS ns.nic.se.
iis.se. 358 IN NS i.ns.se.
iis.se. 358 IN NS ns3.nic.se.
abbekaslagerologistik.se. 120 IN NS ns1.teleservice.net.
abbekaslagerologistik.se. 120 IN NS ns2.teleservice.net.
With whitespaces marked (→
is tab, ·
is space, ¶
newline):
> dig +noall +answer ns iis.se abbekaslagerologistik.se | whitespace
iis.se.→→→208→IN→NS→ns.nic.se.¶
iis.se.→→→208→IN→NS→i.ns.se.¶
iis.se.→→→208→IN→NS→ns3.nic.se.¶
abbekaslagerologistik.se.·120→IN→NS→ns1.teleservice.net.¶
abbekaslagerologistik.se.·120→IN→NS→ns2.teleservice.net.¶
This output is not machine friendly, it is rather human friendly :-) This has the effect than when machine friendly tools, such as cut
are used, the output becomes both human and machine hostile:
> dig +noall +answer ns iis.se abbekaslagerologistik.se | cut -f1,4,5
iis.se. 3417 IN
iis.se. 3417 IN
iis.se. 3417 IN
abbekaslagerologistik.se. 118 ns1.teleservice.net.
abbekaslagerologistik.se. 118 ns2.teleservice.net.
> dig +noall +answer ns iis.se abbekaslagerologistik.se | cut -f1,4,5 | whitespace
iis.se.→3244→IN¶
iis.se.→3244→IN¶
iis.se.→3244→IN¶
abbekaslagerologistik.se.·120→ns1.teleservice.net.¶
abbekaslagerologistik.se.·120→ns2.teleservice.net.¶
What is the expected correct behavior?
Illustration using sed
and tr
to provide expected behavior. sed
to get rid of spaces, and tr
to get rid of double tabs (and converted spaces). This command line is based on bashisms (i.e. $'\t'
), which most shells seem to support.
> dig +noall +answer ns iis.se abbekaslagerologistik.se | sed 's/ /\t/g' | tr -s $'\t' | cut -f1,4,5
iis.se. NS ns.nic.se.
iis.se. NS i.ns.se.
iis.se. NS ns3.nic.se.
abbekaslagerologistik.se. NS ns1.teleservice.net.
abbekaslagerologistik.se. NS ns2.teleservice.net.
And with whitespace to illustrate the machine friendlyness:
> dig +noall +answer ns iis.se abbekaslagerologistik.se | sed 's/ /\t/g' | tr -s $'\t' | cut -f1,4,5 | whitespace
iis.se.→NS→ns.nic.se.¶
iis.se.→NS→i.ns.se.¶
iis.se.→NS→ns3.nic.se.¶
abbekaslagerologistik.se.→NS→ns1.teleservice.net.¶
abbekaslagerologistik.se.→NS→ns2.teleservice.net.¶
Relevant configuration files
Defaults
Relevant logs and/or screenshots
See above
Possible fixes
I have not looked into the codebase (yet), unsure if I will since it is possible to work around it.