Home:ALL Converter>remove certain javascript from html

remove certain javascript from html

Ask Time:2011-04-23T00:12:54         Author:Amol

Json Formatter

I want to remove following javascript from html file.

<script src="text/javascript>
alert('hello');

})();

</script>

and

<script src="text/javascript>
alert('hello');
} catch(err) {}</script>

By reading http://www.cyberciti.biz/faq/sed-howto-remove-lines-paragraphs/ I can use:

sed '/<script type="text\/javascript"/,/<\/script>/d'

but it will remove all the javascript.

My specific requirement is javascript one ending with })(); (new line)</script> and other ending with } catch(err) {}</script>

I want to use sed, if not possible then any program similar to sed so that I can run it through script.

Thank you for taking your time.

Author:Amol,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/5757433/remove-certain-javascript-from-html
ghostdog74 :

Use awk or a programming language of your choice\n\nawk -vRS=\"</script>\" '/<script/ { if(/}\\)\\(\\);|catch\\(err\\)/) { gsub(/script.*/,\"\");} }1' file\n",
2011-04-23T11:22:30
yy