Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (s) sed(1)
5. A sample sed script follows:
:join
/\\$/{N
s/\\\n//
b join
}
This sed script joins each line that ends with a \ (backslash) to the line that follows it.
First, the pattern /\\$/ selects a line that ends with a \ for the group of commands enclosed
in {}. The N subcommand then appends the next line, embedding a newline character.
The s/\\\n// deletes the \ (backslash) and embedded newline character. Finally, b join
branches back to the label :join to check for a \ (backslash) at the end of the newly
joined line. Without the branch, sed writes the joined line and reads the next one before
checking for a second \ character.
The N subcommand causes sed to stop immediately if there are no more lines of input
(that is, if N reads the End-of-File character). It does not copy the pattern space to stan-
dard output before stopping. This means that if the last line of the input ends with a \
(backslash) character, then it is not copied to the output.
RELATED INFORMATION
Commands: awk(1), grep(1), vi(1).
527188-007 Hewlett-Packard Company 8−7