2

我将如何在所有这些标签和符号之间获取以下标题文本?

我需要抓住的东西:

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>

我试过这样做,但它甚至在 pre 标签之前也抓住了整个顶部,但下面的部分似乎工作正常,除了它也抓住 = 符号。

sed -n '/<pre>=/,/=/p

上述 sed 代码的结果是:

<body><pre>=============================================================
Some Title Here v1.2.3 Some Other Description About the Title in Here
=============================================================

任何有关此的反馈都将受到欢迎。非常感谢,一如既往,StackOverflow 是 Q 和 A 的最佳社区 =)

4

3 回答 3

3

一种使用方式GNU sed

sed -n '/<pre>=/,/=/ { //!p }' file.txt

结果:

Some Title Here v1.2.3 Some Other Description About the Title in Here

解释:

//!p只是告诉sed忽略最后一场比赛。

于 2012-10-11T05:28:42.370 回答
0

更新OP的解决方案:

$ sed -n '/<pre>=/,/=/{/=$/d;p;}' file 
Some Title Here v1.2.3 Some Other Description About the Title in Here

从选定的行范围中,删除以 = 结尾的行,这样您就剩下中间的行了。

于 2012-10-11T05:37:40.247 回答
0

这可能对您有用(GNU sed):

sed '/^<body><pre>=\+$/,/^=\+$/!d;//d' file
于 2012-10-11T05:45:11.483 回答