Delete all string after last matching words
<p>I want to delete all string after last where condition</p>

<p>My input is</p>

<pre><code>DELETE FROM abc T1 WHERE EXISTS (SELECT 1 FROM cdef T2 WHERE T1.a=T2.b)
</code></pre>

<p>Want the output as</p>

<pre><code>DELETE FROM abc T1 WHERE EXISTS (SELECT 1 FROM cdef T2 WHERE
</code></pre>

<p>i have tried it with sed command as</p>

<pre><code>output=`echo DELETE FROM abc T1 WHERE EXISTS (SELECT 1 FROM cdef T2
WHERE T1.a=T2.b) | sed -n -e 's/[Ww][Hh][Ee][Rr][Ee].*//p'`
</code></pre>

<p>but i got output as </p>

<blockquote>
  <p>DELETE FROM abc T1</p>
</blockquote>