How to export named to CSV?

I am really shooting for the moon here but I really want to be able to break down our named.conf file into a CSV file so I can easily see what options are for each zone.

Here are two basic entries as examples:

zone "mywiseguys.com" {
        type slave;
        file "xweb.dir/db.mywiseguys.com";
        masters {10.103.13.60; };
};

zone "hosangit.com" {
        type master;
        file "xweb.dir/db.hosangit.com";
};

I would like to be able to parse the results so
column A = zone
column B = type
column C = file
column D = masters

Is this possible using ksh?

Using awk:

awk '
        BEGIN {
                print "Zone,Type,File,Masters"
        }
        /zone/ {
                c += 1
                gsub ( /\"/, x, $2 )
                Z[c] = $2
        }
        /type/ {
                sub ( /\;/, x, $2 )
                T[c] = $2
        }
        /file/ {
                gsub ( /\"|\;/, x, $2 )
                F[c] = $2
        }
        /masters/ {
                n = match ( $0, /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/, I )
                M[c] = I[0]
        }
        END {
                for ( i = 1; i <= c; i++ )
                        print Z, T, F, M ? M : "NA"
        }
' OFS=, named.conf

Thanks, I see where you are going with the awk command. I tried running it but get

awk: syntax error near line 7
awk: illegal statement near line 7
awk: newline in string near line 7
awk: syntax error near line 11
awk: illegal statement near line 11
awk: illegal statement near line 11
awk: syntax error near line 15
awk: illegal statement near line 15
awk: newline in string near line 15
awk: syntax error near line 19
awk: illegal statement near line 19
awk: syntax error near line 24
awk: illegal statement near line 24

Use nawk or /usr/xpg4/bin/awk instead on SunOS or Solaris.

Working much better.

Now my error is:

nawk: syntax error at source line 19
 context is
                        n = match ( $0, >>>  /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/, <<<  I )
nawk: illegal statement at source line 19

I don't have access to a Solaris env to test this. Try with this change:

        /masters/ {
                n = match ( $0, /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ )
                if ( n )
                        M[c] = sprintf ( "%s", substr ( $0, RSTART, RLENGTH ) )
        }

Worked GREAT! Thank You very much.. that is so awesome

---------- Post updated at 03:27 PM ---------- Previous update was at 02:53 PM ----------

Ran into a weird issue with the script that maybe you'll understand.

named.conf

zone "uk-mywiseguys.com" {
        type master;
        file "corp.dir/db.uk-mywiseguys.com";
};

zone "mywiseguys.com" {
        type master;
        file "corp.dir/mwg.zone";
        also-notify { 12.5.6.1; 20.16.19.13; };
};

zone "ukweb.mywiseguys.com" {
        type master;
        file "mwgcorp.dir/db.ukweb.mywiseguys.com";
};

Result was

uk-mywiseguys.com,master,corp.dir/db.uk-mywiseguys.com,NA
mywiseguys.com,master,,NA
corp.dir/mwg.zone;,,corp.dir/mwg.zone,NA
ukweb.mywiseguys.com,master,corp.dir/db.ukweb.mywiseguys.com,NA

Notice how it totally tripped on the second entry. Weird.

Another weird thing...
named.conf

zone "ourholychurch.com" {
        type master;
        file "primary.dir/db.ourholychurch.com";
};

// =====================================
// keyword: start mwgcorp
// Zone files for /var/named/mwgcorp.dir
// Domains owned by MyWiseGuys Corporation
// =====================================

zone "aa-mwg.com" {
        type slave;
        file "corp.dir/db.aa-mwg.com";
        masters {20.10.3.6; };
};

Results

ourholychurch.com,master,Zone,NA
aa-mwg.com,slave,corp.dir/db.aa-mwg.com,20.10.3.6

The first one didn't work so good.... weird.

I got it. Replace /zone/ { with /^zone/ {

Yep.. tried that and it seemed to fix most of the issues.

Some reason I am getting just the word type or file in the fields instead of the actual setting. I thought it might have spacing versus a tab. Not sure why else it would do this randomly throughout the named.conf

Again, thank you Yoda for your help.

---------- Post updated at 11:17 PM ---------- Previous update was at 10:25 PM ----------

I figured out a pattern to the one's I'm having issues with.
example code from named.conf

zone "djzah.com" {
        type slave;
        file "corp.dir/db.djzah.com";
        masters {20.10.3.65; };
};

// =====================================
// keyword: start brands
// Zone files for /var/named/brands.dir
// =====================================

// zone "ourholychurch.com" {
//        type master;
//        file "brands.dir/db.ourholychurch.com";
// };

output

djzah.com,type,file,20.10.3.65

instead of

djzah.com,slave,corp.dir/db.djzah.com,20.10.3.65

So it appears if the following lines are commented out it messes with the previous line. Does that make sense? That's the consistent pattern happening. Weird.

Just wanted to let you know a suggestion from RudiC to add the following to ignore comments at the beginning of the script, fixed my issue.

/^\/\//{next}

Just wanted to share.