FIGURE 1: Simplified SED Syntax

SED Syntax

Command Format

[address] function [arguments]

Address


Address Strings That Specify Special Characters

Character Specifies
^ Beginning of line
$ End of line
. Wildcard, any character
. Wildcard, any character
X+ One or more occurrence of X
X* Zero or more occurrences of X
[] A set of characters: For example, [Aa] accepts both upper- and lowercase A, [A-Z] accepts the range of A to Z, and [A-Za-z0-9] accepts the ranges of A to Z or a to z or 0 to 9.

Special characters require a preceding backslash (\) character for SED to treat them as literal characters. For example, if you want to use the ^ character as part of the pattern match, you must precede it with a backslash to override the ^ special meaning at the beginning of a line:

\\=\
\[=[
\]=]
\$=$
\^=^

Functions

Function Specifies
a line Add a line after each selected line.
c line Change--Replaces each selected line with the specified line.
d Delete each selected line.
i line Insert a line before each selected line.
p Print--Place the current line on stdout (duplicate current line).
q(omega) Quit--Stop processing lines after processing the selected line.
r file Read--Insert file contents after line.
s/string1/string2/ Substitute string1 with string2 in each selected line.
s/string1/string2/g Globally substitute string1 with string2 in each selected line (all occurrences of \string1).