For reasons I won't go into here, I need to make a copy of an old CentOS 5.10 server's named.conf file and perform some text manipulation on the copy. The final result should consolidate each zone's info into a single, separate line. Plus, I need to script it so it can be run as a cron job. Here's an example of what I'm starting with:
zone "." {
        type hint;
        file "named.root";
};
zone "somedomain.com" {
        type master;
        file "somedomain.net";
        allow-transfer {
                11.11.11.11;
                22.22.22.22;
                common-allow-transfer;
        };
};
zone "otherdomain.com" {
        type master;
        file "otherdomain.com";
        allow-transfer {
                33.33.33.33;
                44.44.44.44;
                55.55.55.55;
                common-allow-transfer;
        };
};
And here's an example of what should appear in the edited file:
zone "." { type hint; file "named.root"; };
zone "somedomain.com" { type master; file "somedomain.net"; allow-transfer { 11.11.11.11; 22.22.22.22; common-allow-transfer; }; };
zone "otherdomain.com" { type master; file "otherdomain.com"; allow-transfer { 33.33.33.33; 44.44.44.44; 55.55.55.55; common-allow-transfer; }; };
My CIO and I unsuccessfully searched for existing scripts that convert named.conf into one-line-per-zone format. Using tr and sed, I've managed to 1) turn all tabs into spaces and 2) compress multiple contiguous spaces into a single space. The result is closer to what I need, but I'm still having trouble deleting unwanted newlines while keeping desired newlines. Here's example output which is close to being correct:
zone "." {
 type hint;
 file "named.root"; 
};
zone "somedomain.com" {
 type master;
 file "somedomain.net";
 allow-transfer {
 11.11.11.11;
 22.22.22.22;
 common-allow-transfer;
 };
};
zone "otherdomain.com" {
 type master;
 file "otherdomain.com";
 allow-transfer {
 33.33.33.33;
 44.44.44.44;
 55.55.55.55;
 common-allow-transfer;
 };
};
Tested a few suggested sed, awk, and tr expressions to solve the newline problem, but none of the expressions gave the desired output. Any suggestions you have--even a general direction like "experiment with sed and x,y,z"--would be very appreciated. Thanks!