Command
|
Description
|
#
|
Adds a comment.
|
=
|
The "=" command prints the current line number to standard output.
|
a \
|
The "a" command appends text after the text range or pattern.
|
b label
|
The "b" command branches to the label. You can specify a label with a text string
followed by a colon. If no label is there, branch to the end of the script.
|
c \ text
|
The "c" command changes the current line with text.
|
d
|
The "d" command deletes the current pattern space, reads in the next line, puts
the new line into the pattern space, and aborts the current command, and starts
execution at the first sed command.
|
D
|
The "D" command deletes the first portion of the pattern space, up to the new line
character, leaving the rest of the pattern alone.
|
g
|
Instead of exchanging (the "x" command) the hold space with the pattern space, you
can copy the hold space to the pattern space with the "g" command.
|
G
|
If you want to append to the pattern space, use the "G" command.
|
h
|
The "h" command copies the pattern buffer into the hold buffer.
|
H
|
The "H" command allows you to combine several lines in the hold buffer. It acts
like the "N" command as lines are appended to the buffer, with a "\n" between the
lines. You can save several lines in the hold buffer, and print them only if a particular
pattern is found later.
|
i \ text
|
You can insert text before the pattern with text the "i" command.
|
l
|
The "l" command prints the current pattern space. It is therefore useful in debugging
sed scripts. It also converts unprintable characters into printing characters by
outputting the value in octal preceded by a "\" character.
|
n
|
The "n" command will print out the current pattern space (unless the "-n" flag is
used), empty the current pattern space, and read in the next line of input.
|
N
|
The "N" command does not print out the current pattern space and does not empty
the pattern space. It reads in the next line, but appends a new line character along
with the input line itself to the pattern space.
|
p
|
Another useful command is the print command: "p". If sed wasn't started with an
"-n" option, the "p" command will duplicate the input. The "p" command prints the
entire pattern space.
|
P |
The "P" command only prints the first part of the pattern space, up to the NEWLINE
character.
|
q
|
There is one more simple command that can restrict the changes to a set of lines.
It is the "q" command: quit. This command is most useful when you wish to abort
the editing after some condition is reached.
|
r filename
|
The "r" command will append text from filename after the range or pattern.
|
s/regex/replacement/
|
The substitute command replaces all occurrences of the regular expression (regex)
with replacement
|
t label
|
You can execute a branch if a pattern is found. You may want to execute a branch
only if a substitution is made. The command "t label" will branch to the label if
the last substitute command modified the pattern space.
|
w filename
|
With this command, you can specify a filename that will receive the modified data.
|
x
|
The "x" command exchanges the hold buffer and the pattern buffer.
|
y/source/destination/
|
Transliterate the characters in the pattern space, which appear in source to the
corresponding character in destination.
|