I've been trying to use sed to accomplish the following. Let's say I have the following file (note: my actual file is more complicated than this):
hello world
foo bar
people people
target
something
done
I want to check if target exists between two patterns, in this example, between lines foo bar and done (both lines inclusive), and delete the whole pattern if the target does exist.
I know how to delete the lines between the two patterns using this sed command:
sed '/people.*/,/done/d' file
But I want only to delete it if the string target exists in between the two string matches.
My logic has been something like this:
sed -n '/people.*/,/done/p' file | check if target string exists | delete entire pattern found by sed
EDIT
I forgot to mention that there can be any number of words before target and after target on the same line.