Raw Input Desired Output
cats meow in the meadow 
dogs bark in the yard
pigs sleep in the garden
I have a cat and a dog
birds fly in the blue sky
I have a cat and a dog
Script and Comments
Script1
[ 1] /PAT/h
[ 2] $!d
[ 3] x
Comments
  1. 'Pattern space' and 'Hold space' are abbreviated to 'PS' and 'HS', respectively.
  2. Every time we find a line containing PAT, we save it to HS by command 'h' (previously saved line will be overwritten) in [1].
  3. At the end of the file, command 'x' will exchange the contents of PS and HS. Before termination, sed will print the content of PS automatically. The last line containing PAT is listed.
  4. Drawbacks: When the file does NOT have any line containing PAT, this script will print a blank line rather than nothing. Improved version is shown in next script.
Script2
[ 1] /PAT/h
[ 2] $!d
[ 3] x
[ 4] /^$/d