【发布时间】:2012-09-25 16:19:10
【问题描述】:
我有一个包含以下内容的 html 文件。我想使用 sed 删除模式 < script ..... > 和 </script> 之间的所有内容(多行),其余部分保持原样。我也想去掉标签。
任何帮助将不胜感激。谢谢! 我尝试了以下两种方法,但都没有成功。
cat test.html | tr -d '\n' | sed 's/< script.*<\/script>//g' > output.txt
和
sed '/< script/,/<\/script>/d' test.html > output.txt
don't touch this.
this is not to be removed < script bla bla> this is to be
removed. < /script> this is going to
stay < script bla bla bla bla bla> remove this
and this
and this < /script> and this stays as is.
this too.
【问题讨论】:
-
<script>和</script>会出现在同一行吗? -
显然是 * 上第二受欢迎的问题 - “如何删除 .. sed .. 在两个模式之间?” :) *.com/search?q=sed+patterns