Grep-获取标记所有出现之间的文本

Grep-获取标记所有出现之间的文本,grep,Grep,我即将从中得到我所需要的: grep -o '<div class="item">.*</div>' file.html > result.html 但是我越来越 <div class="item">text</div><h3>Hello</h3><div class="item">text2</div> textHellotext2 如何更正?尽管我建议使用专门的工具来解析HTML或XM

我即将从中得到我所需要的:

grep -o '<div class="item">.*</div>' file.html > result.html
但是我越来越

<div class="item">text</div><h3>Hello</h3><div class="item">text2</div>
textHellotext2

如何更正?

尽管我建议使用专门的工具来解析
HTML
XML
,但您可以使用该模式并将其解释为与Perl兼容的正则表达式(PCRE)
grep-p

grep -oP '(?<=<div class="item">)[^<]*' file.html

有没有一种不用-P标志的方法?这是GNU grep,对吗?对,
GNU grep
用于
positive lookback
。。。。。如果没有
-P选项
,使用双通行证,请想一想
grep-o'[^]*$'
谢谢,就这样!
<div class="item">text</div><h3>Hello</h3><div class="item">text2</div>
grep -oP '(?<=<div class="item">)[^<]*' file.html
text
text2