Let's look at an example of the next command in which we delete a
blank line only when it follows a pattern matched on the previous
line. In this case, a writer has inserted a blank line after a
section heading macro (.H1). We want to remove
that blank line without removing all blank lines in the file. Here's
the sample file:
.H1 "On Egypt"
Napoleon, pointing to the Pyramids, said to his troops:
"Soldiers, forty centuries have their eyes upon you."
The following script removes that blank line:
/^\.H1/{
n
/^$/d
}
You can read this script as follows: "Match any line beginning with
the string `.H1', then print that line and read in the next line. If
that line is blank, delete it." The braces are used to apply multiple
commands at the same address.
In a longer script, you must remember that commands occurring
before the next command will not be applied to the new input line, nor
will commands occuring after it be applied to the old input line.