Label a line in the script for the transfer of control by b or t. label may contain up to seven characters. (The POSIX standard says that an implementation can allow longer labels if it wishes to. GNU sed allows labels to be of any length.)
Write to standard output the line number of addressed line.
text
Append text following each line matched by address. If text goes over more than one line, newlines must be "hidden" by preceding them with a backslash. The text will be terminated by the first newline that is not hidden in this way. The text is not available in the pattern space and subsequent commands cannot be applied to it. The results of this command are sent to standard output when the list of editing commands is finished, regardless of what happens to the current line in the pattern space.
Transfer control unconditionally (branch) to :label elsewhere in script. That is, the command following the label is the next command applied to the current line. If no label is specified, control falls through to the end of the script, so no more commands are applied to the current line.
text
Replace (change) the lines selected by the address with text. When a range of lines is specified, all lines as a group are replaced by a single copy of text. The newline following each line of text must be escaped by a backslash, except the last line. The contents of the pattern space are, in effect, deleted and no subsequent editing commands can be applied to it (or to text).
Delete line(s) from pattern space. Thus, the line is not passed to standard output. A new line of input is read and editing resumes with first command in script.
Delete first part (up to embedded newline) of multiline pattern space created by N command and resume editing with first command in script. If this command empties the pattern space, then a new line of input is read, as if the d command had been executed.
Copy (get) contents of hold space (see h or H command) into the pattern space, wiping out previous contents.
Append newline followed by contents of hold space (see h or H command) to contents of the pattern space. If hold space is empty, a newline is still appended to the pattern space.
Copy pattern space into hold space, a special temporary buffer. Previous contents of hold space are wiped out.
Append newline and contents of pattern space to contents of the hold space. Even if hold space is empty, this command still appends the newline first.
text
Insert text before each line matched by address. (See a for details on text.)
List the contents of the pattern space, showing nonprinting characters as ASCII codes. Long lines are wrapped.
Read next line of input into pattern space. Current line is sent to standard output. New line becomes current line and increments line counter. Control passes to command following n instead of resuming at the top of the script.
Append next input line to contents of pattern space; the new line is separated from the previous contents of the pattern space by a newline. (This command is designed to allow pattern matches across two lines. Using \n to match the embedded newline, you can match patterns across multiple lines.)
Print the addressed line(s). Note that this can result in duplicate output unless default output is suppressed by using "#n" or the -n command-line option. Typically used before commands that change flow control (d, n, b) and might prevent the current line from being output.
Print first part (up to embedded newline) of multiline pattern space created by N command. Same as p if N has not been applied to a line.
Quit when address is encountered. The addressed line is first written to output (if default output is not suppressed), along with any text appended to it by previous a or r commands.
Read contents of file and append after the contents of the pattern space. Exactly one space must be put between r and the filename.
Substitute replacement for pattern on each addressed line. If pattern addresses are used, the pattern // represents the last pattern address specified. The following flags can be specified:
Replace nth instance of /pattern/ on each addressed line. n is any number in the range 1 to 512, and the default is 1.
Replace all instances of /pattern/ on each addressed line, not just the first instance.
Print the line if a successful substitution is done. If several successful substitutions are done, multiple copies of the line will be printed.
Write the line to file if a replacement was done. A maximum of 10 different files can be opened.
Test if successful substitutions have been made on addressed lines, and if so, branch to line marked by :label. (See b and :.) If label is not specified, control falls through to bottom of script.
Append contents of pattern space to file. This action occurs when the command is encountered rather than when the pattern space is output. Exactly one space must separate the w and the filename. A maximum of 10 different files can be opened in a script. This command will create the file if it does not exist; if the file exists, its contents will be overwritten each time the script is executed. Multiple write commands that direct output to the same file append to the end of the file.
Exchange contents of the pattern space with the contents of the hold space.
Transform each character by position in string abc to its equivalent in string xyz.