If I understood your question correctly then it can be achieved in one single sed command:
sed '/<div>/I{:A;N;h;/<\/div>/I!{H;bA};/<\/div>/I{g;/\bsome text here\b/Id}}' file.txt
Testing
Let's say this is your file.txt:
a. no-div text
<DIV>
some text here
1. if this text is matched, remove whole DIV
some other text -- WILL MATCH
</div>
<div>
awesome text here
2. if this text is matched, remove whole DIV
this will NOT be matched
</div>
b. no-div text
<Div>
another text here
3. if this text is matched, remove whole DIV
and this too will NOT be matched
</Div>
<div>
Some TEXT Here
4. if this text is matched, remove whole DIV
foo bar foo bar - WILL MATCH
</DIV>
c. no-div text
Now when I run above sed command it gives this output:
a. no-div text
<div>
awesome text here
2. if this text is matched, remove whole DIV
this will NOT be matched
</div>
b. no-div text
<Div>
another text here
3. if this text is matched, remove whole DIV
and this too will NOT be matched
</Div>
c. no-div text
As you can verify from above output that wherever the pattern some text here
was matched between div
tags those div blocks have been completely removed.
PS: I am doing case insensitive search here, if you don't need that behavior please let me know. I will just need to remove I
switch from above sed commands.