<table name="content_analyzer" another-key="id9">
<type="global" />
</table>
<table name="content_analyzer2" another-key="id12">
<type="global" />
</table>
<table name="content_analyzer" primary-key="id9">
<type="global" />
</table>
<table name="content_analyzer2" primary-key="id12">
<type="global" />
</table>
<table name="content_analyzer_items" primary-key="id56">
<type="global" />
</table>
如果我想提取名称的值,那么:
grep -Po 'name="\K.*?(?=")'
但是,如何同时处理名称和主键的值呢?例如,下面的行不起作用。
grep -Po 'name="\K.*?(?=") primary-key="\K.*?(?=")'
所以看起来就像
content_analyzer id9
content_analyzer2 id12
content_analyzer_items id56
发布于 2016-04-03 14:21:14
不能使用“查找周围”regexp按预期选择行的多个部分。
但是,由于您使用perl语法,也许perl
本身是一个更好的选择:
$ perl -ne 'print if s/.*name="(.*?)".*primary-key="(.*?)".*/\1 \2/' file
content_analyzer id9
content_analyzer2 id12
content_analyzer_items id56
这不使用任何查找结构,而且是不言自明的。
https://unix.stackexchange.com/questions/274009
复制相似问题