如何在grep中找到其他单词之间的世界?

如何在grep中找到其他单词之间的世界?,grep,Grep,我有xml文件,我需要在它们之间找到一些文本 我知道 grep-oE“()(.+)()”glTextureView.xml 输出是 <titel> assa </titel> assa 这是合乎逻辑的。如何仅输出assa?我还写道: grep -oE "(<title>)(.+)(</title>)" glTextureView.xml | grep -v "</?title>" grep-oE”(.+)()“glTextur

我有xml文件,我需要在它们之间找到一些文本 我知道

grep-oE“()(.+)()”glTextureView.xml
输出是

<titel> assa </titel>
assa
这是合乎逻辑的。如何仅输出assa?我还写道:

grep -oE  "(<title>)(.+)(</title>)" glTextureView.xml | grep -v "</?title>"
grep-oE”(.+)()“glTextureView.xml | grep-v”

但是我的输出是空的,因为它删除了所有字符串。

首先,您需要知道使用正则表达式解析xml是有风险的

如果您想要快速解决方案,请尝试以下方法:

grep -oP "(?<=<title>)[^<]*" foo.xml

grep-oP”(?谢谢!这是工作,但我在grep中是新手。你能解释一下这是什么意思吗?@user3288344它是lookbehind。在
之后匹配文本。google regex lookbehind查找更多示例。
grep -oP "(?<=<title>)[^<]*" foo.xml