[英]How can I remove html tags, scripts, empty lines in a HTML with sed?
[英]How can I remove comments in a HTML with sed?
例如我有這個 html 代碼
<h3>Title</h3>
<!--comment-->
<!-- comment -->
<!--
comment
-->
<h2>Title2</h2>
和 sed 我必須得到這個
<h3>Title</h3>
<h2>Title</h2>
我在這里找到了一些命令,但它們對我不起作用
sed '/<!--.*-->/d'
不刪除這個
<!--
comment
-->
使用有效的 HTML/XML:
xmlstarlet ed -d '//comment()' file.html
如果要就地編輯文件,請添加選項-L
。
如果您的 HTML 無效,請嘗試以下操作:
xmlstarlet format --recover --html file.html | xmlstarlet ed -d '//comment()'
使用 xml:
xmlstarlet format --recover file.xml | xmlstarlet ed -d '//comment()'
要在輸出中省略 xml 聲明,請添加--omit-decl
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.