sed <command> [file...]

Stream editor

Arguments

NameDescription
command
filefilepaths

Subcommands

NameDescription
aAppends `text` after a line
bBranch unconditionally to `label`
cReplace (change) lines with `text`
dDelete the pattern space; immediately start next cycle
DIf pattern space contains newlines, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input. If pattern space contains no newline, start a normal new cycle as if the d command was issued
eExecutes the command that is found in pattern space and replaces the pattern space with the output; a trailing newline is suppressed
FPrints the file name of the current input file
gReplaces the contents of the pattern space with the contents of the hold space
GAppends a newline to the contents of the pattern space, and then appends the contents of the hold space to that of the pattern space
hReplaces the contents of the hold space with the contents of the pattern space
HAppends a newline to the contents of the hold space, and then appends the contents of the pattern space to that of the hold space
iInsert text before a line
lPrints the pattern space in an unambiguous form
nPrints the pattern space, then, regardless, replaces the pattern space with the next line of input. If there is no more input then sed exits without processing any more commands
NAdds a newline to the pattern space, then appends the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands
pPrints the pattern space
PPrints the pattern space up to the first newline
qExit sed without processing any more commands or input
QThis command is the same as q, but will not print the contents of pattern space
rReads file
RQueue a line of filename to be read and inserted into the output stream at the end of the current cycle, or when the next input line is read
s, regexp, replacementMatch the regular-expression against the content of the pattern space. If found, replace matched string with replacement
t(test) Branch to label only if there has been a successful substitution since the last input line was read or conditional branch was taken. The label may be omitted, in which case the next cycle is started
T(test) Branch to label only if there have been no successful substitutions since the last input line was read or conditional branch was taken. The label may be omitted, in which case the next cycle is started
vMakes sed fail if GNU sed extensions are not supported, or if the requested version is not available
wWrites the pattern space to the file
WWrites to the given filename the portion of the pattern space up to the first newline
xExchanges the contents of the hold and pattern spaces
y, src, dstTransliterate any characters in the pattern space which match any of the source-chars with the corresponding character in dest-chars
z(zap) Empties the content of pattern space
#Comment until the next newline

Options

NameDescription
-EInterprets regular expressions as extended (modern) regular expressions rather than basic regular expressions
-aCauses sed to delay opening each file until a command containing the related ``w'' function is applied to a line of input
-e <command>Appends the editing commands specified by the command argument to the list of commands
-f <command_file>Appends 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
-I <extension>Edits files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be saved
-i <extension>Edits files in-place similarly to `-I`, but treats each file independently from other files. In particular, line numbers in each file start at 1, the ``$'' address matches the last line of the current file, and address ranges are limited to the current file
-lMakes output line buffered
-nBy 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
-rSame as `-E` for compatibility with GNU sed
-uMakes output unbuffered