Reputation: 3982
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?
Upvotes: 2
Views: 4171
Reputation: 47099
If the file is well ordered, you could use awk
with automatic record- and field separation:
awk '
BEGIN { RS = ORS = "\n\n"; FS="\n" }
$1 !~ /domain3/
' file
Removes zone where the first line contains "domain3".
Upvotes: 1
Reputation: 241908
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
Upvotes: 7