sed or awk remove multiple lines starting with `if` and ending with that `if`'s closing `fi`
<p>An extension to this question <a href="https://stackoverflow.com/questions/37502712/delete-multiple-lines-from-patterna-match-through-second-occurrence-of-pat">Delete multiple lines - from &quot;patternA&quot; match, through second occurrence of &quot;patternB&quot;</a> ... Thinking I should make it more robust.</p>

<p>So, rather than counting how many <code>fi</code>'s, in the likelihood there may be an unknown amount, I'd like to be able to simply execute something where...</p>

<p>If I have the following file <code>/somepath/somefile</code> containing:</p>

<pre><code>...

# Test something?
if something
then
do something
if somethingelse
then
do somethingelse
fi
fi

...
</code></pre>

<p>...with an unknown amount of possible <code>if</code>/<code>fi</code> statements, how can I remove everything from the line starting with the string containing "<code>something?</code>" through the line containing the closing "<code>fi</code>" to the first <code>if</code>? Any/All help is appreciated. </p>