Using Bash/Sed to delete between identical strings

Hi. I'm hoping that someone can help me with a bash script to delete a block of lines from a file.

What I want to do is delete every line between two stings that are the same,
including the line the first string is on but not the second.

(Marked lines to match with !)
For example if I have:

fish

! cat
dog
ferret
lion
etc
! cat
kitten
zebra

What I'm looking to get is:

fish
cat
kitten
zebra

I've been trying to work out how to do this with sed but haven't had much luck.
Some 3-4 hours in, the closest I've gotten is deleting between the strings, or deleting both strings. :wall:

Thanks for reading. -Zykr

$ awk '!p;/cat/{p=!p}' file
fish
cat
kitten
zebra
1 Like

It works! :slight_smile: Thank you very much for the quick reply . I doubt I would ever have thought of trying to use awk for this since I've never used it for anything but working with large lists of numbers.

Thanks again. -Zykr