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.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder