I would guess that there is a simpler solution with awk, but the following code uses
sed, tr and grep -- three of my favorites -- to solve this.
Code:
> cat file73
blah
blah
ABC
123
456
789
DEF
yech
yech
> sed "s/^ABC/#ABC/" <file73 | sed "s/DEF$/DEF#/" | tr "\n" "~" | tr "#" "\n" | grep "^ABC" | tr "~" "\n"
ABC
123
456
789
DEF