Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 多个相同字符之间的SED正则表达式_Regex_Bash_Sed - Fatal编程技术网

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

Regex 多个相同字符之间的SED正则表达式,regex,bash,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 th

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

我需要抓住的是:

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>
Some Title Here v1.2.3 Some Other Description About the Title in Here
=============================================================
此处的一些标题v1.2.3关于此处标题的一些其他说明
=============================================================
这里有一些其他数据,但我不在乎。。。
我试过这样做,但它在预标记之前也会抓取整个顶部,但下面的部分似乎很好,除了它还抓取=符号

<body><pre>=============================================================
Some Title Here v1.2.3 Some Other Description About the Title in Here
=============================================================
sed '/^<body><pre>=\+$/,/^=\+$/!d;//d' file
sed-n'/=/,/=/p
sed -n '/<pre>=/,/=/ { //!p }' file.txt
上述sed代码的结果为:

=============================================================
此处的一些标题v1.2.3关于此处标题的一些其他说明
=============================================================

对此的任何反馈都将被接受。非常感谢您,StackOverflow始终是Q's and A's=)的最佳社区。

单向使用
GNU sed

说明:


/!p
只是告诉sed忽略最后一个匹配。

更新OP的解决方案:

$sed-n'/=/,/=/{/=$/d;p;}文件
此处的一些标题v1.2.3关于此处标题的一些其他说明
从所选行的范围中,删除以=”结尾的行,这样就剩下了中间的行。

这可能适合您(GNU-sed):

sed'/^=\+$/,/^=\+$/!d//d'文件

这一个可以工作,但仍然可以抓取前面和前面的所有标记,还可以等于(=)下面的符号。但是谢谢:)
$ sed -n '/<pre>=/,/=/{/=$/d;p;}' file 
Some Title Here v1.2.3 Some Other Description About the Title in Here
sed '/^<body><pre>=\+$/,/^=\+$/!d;//d' file