deleting text between two stings

example.txt
----------
this is a line i want to keep
this is another line I wish to keep
I wish to delete from here ON until I see
four new lines from here and then
I wish to keep the rest.
These are some special charcters {)#@ which 
have to be deleted too
This is a one more new line here. delete the text from 
here. The end.

I wish to delete all the text from the word "ON" in the 3rd line
until the word "deleted" using sed.
I appreciate your solutions.

I have tried this so far , It works but there it removes the complete
lines 4 till 7

sed -e /ON/deleted//d example.txt > out.txt
C:\cygwin\tmp>cat example.txt
this is a line i want to keep
this is another line I wish to keep
I wish to delete from here ON until I see
four new lines from here and then
I wish to keep the rest.
These are some special charcters {)#@ which
have to be deleted too
This is a one more new line here. delete the text from
here. The end.

C:\cygwin\tmp>sed s/ON/~ON/ example.txt | sed s/deleted/deleted~/ | tr \n "^" | cut -d"~" -f1,3 | tr "^" \n | tr -d "~"
this is a line i want to keep
this is another line I wish to keep
I wish to delete from here  too
This is a one more new line here. delete the text from
here. The end.

And it shows 'creative' use of sed, cut, tr commands!

Hi, joeyg.

This solution works with this specific data sample, but it will fail badly if the data contains '~' or '^' characters. The presence of '~' characters could cause the cut command to slice things up incorrectly, and any '^' in the original text will be lost and new newlines inserted in their place.

Perhaps you realized this, but I just wanted to point it out in case others did not.

Take care,
alister

My bad for not pointing that out. I specifically chose a couple of characters that are little used, and not present in the example.

sed -e '
 /ON/,/deleted/ {
    /ON/s/ON.*$//p
    /deleted/s/^.*deleted//p
    d
 }' example.txt > out.txt

This solution is greedy. If the word 'deleted' occurs more than once on the line that ends the range, everything until the final 'deleted' will be removed.