如何从给定文件“named.conf”中提取两个字段?我想要字段'zone'和'file'。
zone "example.com" IN {
type master;
file "db.example.com";
allow-query { any; };
allow-update { none; };
allow-transfer { 10.101.100.2; };
};
答案 0 :(得分:3)
这可能对您有用:
sed '/^\s*\(zone\|file\) "\([^"]*\)".*/,//!d;//!d;s//\2/' named.conf
example.com
db.example.com
答案 1 :(得分:2)
试试这个快速& dirty(GNU)AWK程序(保存为zone-file.awk
):
/^zone/, /^}/ {
if (NF == 4) {
zone = $2
next
}
if (NF == 2 && $1 == "file") {
sub(";$", "", $2)
print zone, $2
}
}
对我来说如下:
$ awk -f zone-file.awk /etc/named.conf
"." "named.ca"
"localhost" "localhost.zone"
[...]