我如何在所有这些标签和符号之间获取以下标题文本?
我需要捕获什么:
Some Title Here v1.2.3 Some Other Description About the Title in Here
示例源代码:
<body><pre>=============================================================
Some Title Here v1.2.3 Some Other Description About the Title in Here
=============================================================
some other data here but I don't care about it ...
</pre></body></html>
我尝试过这样做,但它甚至在预标记之前也捕获了整个顶部部分,但下面的部分似乎工作正常,除了它还捕获=符号。
sed -n '/<pre>=/,/=/p
上面 sed 代码的结果是:
<body><pre>=============================================================
Some Title Here v1.2.3 Some Other Description About the Title in Here
=============================================================
任何有关此问题的反馈都将受到欢迎。非常感谢,StackOverflow 一如既往是解答问题和答疑的最佳社区 =)
最佳答案
使用GNU sed
的一种方法:
sed -n '/<pre>=/,/=/ { //!p }' file.txt
结果:
Some Title Here v1.2.3 Some Other Description About the Title in Here
说明:
//!p
只是告诉 sed
忽略最后一个匹配。
关于regex - 多个相同字符之间的 SED 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12832762/