
Command-Line Syntax | 755
sed
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
sed Operation
sed operates as follows:
• Each line of input is copied into a pattern space, an internal buffer where edit-
ing operations are performed.
• All editing commands in a sed script are applied, in order, to each line of
input.
• Editing commands are applied to all lines (globally) unless line addressing
restricts the lines affected.
• If a command changes the input, subsequent commands and address tests are
applied to the current line in the pattern space, not the original input line.
• The original input file is unchanged because the editing commands modify an
in-memory copy of each original input line. The copy is sent to standard out-
put (but can be redirected to a file).
• sed also maintains the hold space, a separate buffer that can be used to save
data for later retrieval.
Command-Line Syntax
The syntax for invoking sed has two forms:
sed [-n] [-e] 'command' file(s)
sed [-n] -f scriptfile file(s)
The first form allows you to specify an editing command on the command line,
surrounded by single quotes. The second form allows you to specify a scriptfile,a
file containing sed commands. Both forms may be used together, and they may be
used multiple times. If no file(s) is specified, sed reads from standard input.
Standard Options
The following options ...