title: bash script to extract values from zone files BIND and update as execute command
body: <p>I am trying to write a script that will extract the records (A,MX,TXT and skip the NS), from BIND zone files. (I've more that 700 zone file)
  in order to execute with command. in new server as this utility (dns) will accept to add records only through this way</p>
  
  <pre><code> /usr/bin/dns -a domain.com -a mail -ip 192.168.5.193
  </code></pre>
  
  <p>lets assume that the zone file like that </p>
  
  <pre><code>$TTL    900
  
  @       IN      SOA     ns1.nameserver.tld. cp.domain.com. (
                          2016120503      ; Serial
                          10800   ; Refresh
                          3600    ; Retry
                          604800  ; Expire
                          10800 ) ; Minimum
  
  domain.com.             IN NS   ns1.nameserver.tld.
  domain.com.             IN NS   ns2.nameserver.tld.
  mail.domain.com.        IN A    192.168.5.193
  domain.com.             IN A    192.168.1.33
  ftp.domain.com.         IN CNAME        domain.com.
  domain.com.             IN MX  10 mail.domain.com.
  </code></pre>
  
  <p>and I need to extract the values (A,MX,CNAME ) with IP and add it on other server with below way ..like that  </p>
  
  <pre><code>/usr/bin/dns -a domain.com -a mail -ip 192.168.5.193
  /usr/bin/dns -a domain.com -cname ftp -canonical domain.com
  /usr/bin/dns -a domain.com -mx -mail mail.domain.com -priority 10
  </code></pre>
  
  <p>Seeing as that is a bit convoluted, especially as the zone files contain different values, some are contain A record only and some contain MX and MX2 and some CNMAE and some not and so on. I'm not sure how to wring the bash I have written more than once but in wrong ways.</p>
  
  <p>Any suggestions?</p>