正则表达式模式与grep for expression2 AFTER表达式1

时间:2017-01-31 10:19:03

标签: regex ubuntu grep

我试图在该标题之后的任何地方找到一堆HTML文件中带有带有特定代理名称的代理的标题。

通常像

<h3>Agent</h3>
<p>Blah blah blah </p>
<p>Their agent is XYZ Corp.</p>

应该找到

但是我不能保证标题和XYZ公司实例之间的内容有任何规律性。所以像DOS这样的东西我可能会搜索'Agent * XYZ'意思

-match the string 'Agent'
-followed by anything
-followed by the string 'XYZ'

如何在Ubuntu上用grep编写? 我试过了

grep -lc 'Agent*XYZ' *.html
grep -lc 'Agent.*?XYZ' *.html
两个都没有成功。我可以在多个文件中手动找到模式,所以我知道它存在。

TIA

1 个答案:

答案 0 :(得分:0)

使grep大小写不敏感并删除非贪婪的?

grep -ilc 'Agent.*XYZ' *.html
#   __^       __^^