How to use sed to append quote characters around a DNS TXT record

Written by - 0 comments

Published on - Listed in DNS PowerDNS Linux Coding Shell


While handling a DNS migration with exported Bind zone files, we came across a problem concerning the TXT records. All the exported zone files contained the TXT records as a non-quoted value:

$ cat zone-example.com | grep TXT
@ 600 IN TXT MS=ms12345678

However when trying to import this zone file into PowerDNS using pdns-util load-zone, the import fails. PowerDNS expects the TXT record values to be quoted.

To handle this across all exported zone files, we used sed's replace function. This keeps the existing record value and wraps it around in double-quotes:

$ cat zone-example.com | grep TXT | sed "s/\(.*\)[[:blank:]]\(TXT\)[[:blank:]]\(.*\)/\1 \2 \"\3\"/g"
@ 600 IN TXT "MS=ms12345678"

Of course this can now be applied to all Bind zone files using sed -i.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.