sed 从缩小的 html 中删除 javascript 调用 [英] sed to remove javascript call from minified html
本文介绍了sed 从缩小的 html 中删除 javascript 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从缩小的 html 文件中删除所有外部 js 调用.但是,如果 js 调用在另一行中,则以下内容将删除(不适用于缩小的 html)
I want to remove all external js call from minified html file. However, the following removes if js call is in another line (not works for minified html)
var=$(sed -e '/^<script.*<\/script>$/d' -e '/.js/!d' testFile.html)
grep -v "$var" "testFile.html" | sponge "testFile.html"
示例输入文件:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title> <script type="text/javascript" src="script.js" language="javascript"></script> <script></script> </head><body></body></html>
示例输出文件:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title> <script></script> </head><body></body></html>
提前致谢
推荐答案
遗憾的是 sed 不支持非贪婪/惰性匹配(很容易).试试 perl:
Unfortunately sed doesn't support non-greedy/lazy match (easily). Try perl:
perl -pe 's/<script.*?script> //'
这篇关于sed 从缩小的 html 中删除 javascript 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文