[英]How to show only first match in pcregrep?
I have xml in log-files, that looks like:我在日志文件中有 xml,看起来像:
<ServiceRs>
1
</ServiceRs>
text text text
<ServiceRs>
2
</ServiceRs>
text
So, i need to cut this XML from log file and i'm trying to do this with:所以,我需要从日志文件中删除这个 XML,我正在尝试这样做:
pcregrep -M '<ServiceRs>(\n|.)*</ServiceRs>'
But after this i didn't get two ServiceRs xml's, i got this:但是在此之后我没有得到两个 ServiceRs xml,我得到了这个:
<ServiceRs>
1
</ServiceRs>
text text text
<ServiceRs>
2
</ServiceRs>
I know, that i can modify pattern - (\\n|.)* -> (\\n|.){0, n), but i really don't know how many lines will be in xml.我知道,我可以修改模式 - (\\n|.)* -> (\\n|.){0, n),但我真的不知道 xml 中有多少行。
Can you try你能试一下吗
pcregrep -M '<ServiceRs>(\\n|.)*?</ServiceRs>'
?
is for lazy match是为了懒惰的比赛
It only matches the content between the <ServiceRs>
and </ServiceRs>
and excludes the rest text text...
s它只匹配
<ServiceRs>
和</ServiceRs>
之间的内容并排除其余的text text...
s
Ref: https://regexr.com/3h1ug参考: https : //regexr.com/3h1ug
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.