Description
The following example use an empty string as PAT1, and `this' as PAT2. Speaking in another way, we want to delete a blank line and the following line if it contains `this'.
Raw Input Desired Output
keep this 
delete this keep this keep this
delete this keep this keep this
keep this
 keep this
  keep this
   keep this
    keep this
Script and Comments
Script1
[ 1] $!N
[ 2] /^\n.*this/d
[ 3] P
[ 4] D
Comments
  1. Pattern Space is abbreviated to `PS'.
  2. Step [1] will append the next line to PS.
  3. After Step [1], PS contains two physical lines:
    • if the first line is a blank one and the second one contains `this', they will be deleted via step [2] and then sed will start a new cycle;
    • otherwise,
      • The first logical line in PS (i.e., the blank one) will be printed by command `P'([3]), then deleted by command `D'([4]);
      • Command `D' will make sed branch to Step [1] to examine the second logical line.