dig
sometimes uses double tabs which is only good for visually viewing lookups of short to medium-length hostnames, but it is bad for reusing the values as in parsing them like a CSV file into a table.
To prevent the double use of tabs, you can pipe as follows:
dig <host> | sed --quiet 's/[\t ]\+/\t/gp'
pipe/forward it to sed and let it replace one or more (greedy) tab or space with a single tab
Thoroughly:
--quiet only output the result
' beginning of script
s command "substitute"
/ seperator
[\t ]\+ replace one or more (greedy) (the plus char is an escaped quantifier) tab or space
/ seperator
\t with a single tab character
/ seperator
gp "global (search through every line)" and "print lines" flag
' end of script
Thanks to:
- http://anaturb.net/sed.htm
- https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/
function digc() #dig-clean
{
dig "$@" | sed --quiet 's/[\t ]\+/\t/gp'
}
Explanation: pass all arguments (i.e. whatever follows after digc
) to usual dig, pipe it as described above