The
sed utility reads the specified files, or the standard input if no files are specified, modifying the input as specified by a list of commands. The input is then written to the standard output.
A single command may be specified as the first argument to
sed. Multiple commands may be specified by using the
-e or
-f options. All commands are applied to the input in the order they are specified regardless of their origin.
The following options are available:
-a
The files listed as parameters for the “w” functions are created (or truncated) before any processing begins, by default. The -a option causes sed to delay opening each file until a command containing the related “w” function is applied to a line of input.
-E
Enables the use of extended regular expressions instead of the usual basic regular expression syntax.
-e command
Append the editing commands specified by the command argument to the list of commands.
-f command_file
Append the editing commands found in the file command_file to the list of commands. The editing commands should each be listed on a separate line.
-n
By default, each line of input is echoed to the standard output after all of the commands have been applied to it. The -n option suppresses this behavior.
-r
Identical to -E, present for compatibility with GNU sed.
The form of a
sed command is as follows:
[address[,address]]function[arguments]
Whitespace may be inserted before the first address and the function portions of the command.
Normally,
sed cyclically copies a line of input, not including its terminating newline character, into a
pattern space, (unless there is something left after a “D” function), applies all of the commands with addresses that select that pattern space, copies the pattern space to the standard output, appending a newline, and deletes the pattern space.
Some of the functions use a
hold space to save all or part of the pattern space for subsequent retrieval.