Command Description
b label
  • Jump to label; if label is not specified, then jump to the end of the script.
  • This is an unconditional branch; see command 't' for a conditional one.
d Clear the contents of pattern space and start a new cycle.
D Delete the first line from pattern space.
Control then passes to the top of the script.
If command 'D' empties the pattern space, a new line will be read in;
otherwise, no new line will be read in.
g Overwrite the contents of pattern space with hold space.
G Append the contents of hold space to pattern space,
separate them by a newline character.
h Overwrite the contents of hold space with pattern space.
H Append the contents of pattern space to hold space,
separate them by a newline character.
i\
TEXT
Print TEXT immediately, where TEXT may consists of several lines.
In this case, each but the last one of TEXT must be ended with a backslash ('\') followed immediately by a newline character.
n Print the contents of pattern space and overwrite it with next line.
Control passes to the command following this 'n'.
N Append next line to pattern space.
Next line is separated from the original pattern space by a newline character.
p Print the contents of pattern space.
P Print the first line of pattern space.
q Print the contents of pattern space then exit.
r Copy the contents of the specified file to STDOUT. The contents of that file will not be shown immediately until the end of the script is reached, or command N/n is executed.
s/RE/Str/F Replace the First string of the line matched RE with Str. Where F may be empty or consisting of the following flags:
  • a number: to specify which matched string of the line to be replaced,
  • `g': to replace every matched string, or
  • `p': to print the contents of the Patten Space if the substitution is made.
t
  • This is a conditional branch; see command 'b' for a non-conditional one.
  • Jump to label if any successful substitution has been made on the pattern space since
    • the last input line was read, or
    • the last conditional branch (t label) has taken.
  • If label is not specified, then jump to the end of the script.
w Write the contents of pattern space to the file specified after the w command.
x Exchange the contents of pattern space and hold space.