Sed linux演示了如何用文本包装多行搜索模式

Sed linux演示了如何用文本包装多行搜索模式,sed,Sed,我有一个html文件,其中包括以下部分: <div id='webnews'> ... variable stuff ... </div> <!-- <div id='webnews'> ... variable stuff ... </div> --> sed '/<div id="webnews"/, /<\/div>/ { p }' filename.html ... 可变的东西。。。 我想评论如下:

我有一个html文件,其中包括以下部分:

<div id='webnews'>
... variable stuff ...
</div>
<!--
<div id='webnews'>
 ... variable stuff ...
</div>
-->
sed '/<div id="webnews"/, /<\/div>/ { p }' filename.html

... 可变的东西。。。
我想评论如下:

<div id='webnews'>
... variable stuff ...
</div>
<!--
<div id='webnews'>
 ... variable stuff ...
</div>
-->
sed '/<div id="webnews"/, /<\/div>/ { p }' filename.html

我可以按如下方式查找和打印多行文本:

<div id='webnews'>
... variable stuff ...
</div>
<!--
<div id='webnews'>
 ... variable stuff ...
</div>
-->
sed '/<div id="webnews"/, /<\/div>/ { p }' filename.html

sed'/sed不是适合该作业的工具

使用:

sift-m'(.+)(.*)(.+)'--用sed替换“$1$3”

快速脏(除非您确定html内容/结构,否则这不是html的最佳方法)

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

sed-e'//,//!b;//i\'文件
或许:

sed $'/<div id=.webnews.>/,/<\/dev>/{/<div id=.webnews.>/i\<!--\n;/<\/div>/a\-->\n}' file
sed$'/,//{//i\\n}文件

Nice工具。不幸的是,它提取与模式匹配的数据,而不是在输出流中替换,并且对终止模式的贪婪捕获远远超出预期。