Q:

How to remove a text block from a file with bash

I have file of bind config with following config:
zone "domain1.com" {
        type master;
        file "masters/domain1.com";
        allow-transfer {
                dnscontroller_acl;
        };
};

zone "domain2.com" {
        type master;
        file "masters/domain2.com";
        allow-transfer {
                dnscontroller_acl;
        };
};

zone "domain3.com" {
        type master;
        file "masters/domain3.com";
        allow-transfer {
                dnscontroller_acl;
        };
};

zone "domain4.com" {
        type master;
        file "masters/domain4.com";
        allow-transfer {
                dnscontroller_acl;
        };
};

How to remove zone config (start from zone filename and end of };) from file with help of bash?

A:

You can use sed to remove the config for a given zone:
sed '/^zone "domain4.com" {$/,/^};/d' file

If you want a script that can take a zone as an argument, just add the she-bang and the argument:
#!/bin/bash
sed '/^zone "'"$1"'" {$/,/^};/d' file

