Some Terminology Related to sed

Pattern Space
  1. You can think of 'Pattern Space' as a buffer.
  2. Each time sed read in a line, it will be placed here for further editing.
    There is one another 'buffer' named Hold Space
  3. Usually we keep one line in Pattern Space. sed provides some advanced commands to keep several lines in pattern space where lines are separated by newline characters.
Each cycle consists of
  1. Overwriting Pattern Space with next line.
  2. Execute commands from top of the script on the Pattern Space.
  3. If the end of the script (not the data file!) is reached,
    print the contents of Pattern Space
    (this default action can be disabled by the '-n' option).
Hold Space
Another 'buffer', relevant commands are x, h, g, and G