我有一个标准的.Net.csproj xml文件,其中包含xml标记和它们之间的文本,如下所示:
<lorem>ipsum</lorem>
<PackageReleaseNotes>Some information.
- Some more information.</PackageReleaseNotes>
<lorem>ipsum</lorem>
我需要一个bash命令来提取<PackageReleaseNotes>
和</PackageReleaseNotes>
标记之间的文本、换行符等。
我提出了cat Useful.String.Extensions.csproj | grep -o -P '(?<=PackageReleaseNotes>).*(?=</PackageReleaseNotes>)'
,如果标记之间的文本没有换行符,它就可以工作。但对于我举的例子来说,它什么也不返回。
cat Useful.String.Extensions.csproj | grep -Pzo '(?<=PackageReleaseNotes>)(.|n)*(?=</PackageReleaseNotes>)'
-z/--null-data
Treat input and output data as sequences of lines.