Raw Input
1 cat chicken
2 bird dog apple
3 dog orange cat
4 cat juice coffee
5 cow milk dog
Desired Output
3 dog orange cat
Script and Comments
Script1
[ 1] /PAT1/!d
[ 2] /PAT2/!d
Comments
  1. Any line without PAT1 will be discarded in [1]. In this case sed will start next cycle.
  2. Lines survived from [1] contain PAT1. If they do not contain PAT2, they will be discarded in [2].
  3. After [2], sed will print the survived line and start next cycle.