regex - 多个相同字符之间的 SED 正则表达式

标签 regex bash sed

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

我需要捕获什么:

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/

相关文章:

java - 确定 Java 程序是否已从交互式 shell 启动

bash - docker 。无法使用 ssh 命令启动 docker 容器

linux - 在文件的每一列上添加 1-10 分钟,并且文件有 n 次

c - 使用 Regex (POSIX) 在 #ifdef 语句外查找 printf() 调用

regex - 反转正则表达式,从正则表达式创建字符串

python - 从多个列表中的多个元素查找文本文件中的模式?

bash - Unix:If/then 语句始终为假

regex - ActionScript 3正则表达式匹配

sed - <"$fileVariableName"> 在 csh 中做什么?

linux - 我可以在 Linux 中用所有文件中的新内容更新文件的一部分吗