0
I have a block of text I need to delete, however, only if it contains specific text inside the block:
...
<script language="JavaScript">
var somethingA = 0;
var somethingB = 0;
var somethingC = 0;
// do some stuff
</script>
<script language="JavaScript">
var somethingA = 0;
var somethingC = 0;
var somethingD = 0;
// do some stuff
</script>
....
I want to remove only the <script>
block that has var somethingB
in it. There could be any number of <script>
blocks in the file in any position.
I was hoping to use sed doing something like:
sed 's/<script/,/<\/script>/ D'
However, I can't figure out how to only delete the block with var somethingB
in it.
PS: I could also use perl or awk. I would rather use sed for consistency sake, but if it is easier in perl and/or awk I would switch gears pretty quick at this point. Thanks!
The canonical "don't parse html with regex" answer...
– glenn jackman – 2014-12-30T02:32:38.227@glennjackman Let's pretend it's not HTML ;-) – Matt – 2014-12-30T13:56:50.447