1

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"

Sample input file:

<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>

Sample output file:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JavaScript Ders 2</title> <script></script> </head><body></body></html>

Thanks in advance

unh
  • 61
  • 5

1 Answers1

0

Unfortunately sed doesn't support non-greedy/lazy match (easily). Try perl:

 perl -pe 's/<script.*?script> //'
lojza
  • 1,823
  • 2
  • 13
  • 23
  • Thanks, it works! I want to also check it contains .js in this match. How can I do that? – unh Jul 18 '18 at 14:28