正则表达式从文件中提取多行

标签 regex linux perl sed awk

如何从给定文件“named.conf”中提取两个字段?我想要“区域”和"file"字段。

zone "example.com" IN {
        type master;
        file "db.example.com";
        allow-query { any; };
        allow-update { none; };
        allow-transfer { 10.101.100.2; };
};

最佳答案

这可能对你有用:

sed '/^\s*\(zone\|file\) "\([^"]*\)".*/,//!d;//!d;s//\2/' named.conf
example.com
db.example.com

关于正则表达式从文件中提取多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9384787/

相关文章:

C++ 使用单词列表作为分隔符拆分字符串

android - System.currentTimeMillis() 在华为上返回错误的时间戳

java - 调用外部类和方法

python - 如何将依赖树的输出解析为扁平结构

Java 正则表达式 : how to find a short word inside a longer one

c++ - 如何检查 c++11 std::regex_replace 是否成功?

linux - 无法在 OSX Yosemite 上启动 docker

perl - 是否有与 Buildout 或 RVM 等效的 Perl?

python - perl 相当于 python array.array(typecode, ..)

mysql - 更改 Mysql 全局变量