Raw Input Desired Output
Line 1
Line 2 PAT
Line 3
Line 4 
Line 5
Line 6 PAT
Line 7
Line 8
Line 9
Line 10
Line 1
Line 5
Line 9
Line 10
Script and Comments
Script1
[ 1] /PAT/!b
[ 2] $!N
[ 3] $!N
[ 4] d
Comments
  1. The Pattern Space is abbreviated to `PS'.
  2. If a line is not the one we want to delete, command `b' of Step [1] will make sed branch to the end of this script, print the contents of PS (that line), then start a new cycle.
  3. Steps [2] and [3] will append to the end of PS the next 2 lines following a line containing PAT.
  4. Since GNU sed will print the contents of PS when it performs command `N' on the last line of a file, we precede command `N' of Step [2] (and [3], too) with $! to instruct sed not to perform command `N' on the last line of a file.