O'Reilly logo

Unix in a Nutshell, 4th Edition by Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Group Summary of sed Commands

In the lists that follow, the sed commands are grouped by function and are described tersely. Full descriptions, including syntax and examples, can be found in the following section, "Alphabetical Summary." Commands marked with a | are specific to GNU sed.

Basic Editing

a\

Append text after a line.

c\

Replace text (usually a text block).

i\

Insert text before a line.

d

Delete lines.

s

Make substitutions.

y

Translate characters (like Unix tr).

Line Information

=

Display line number of a line.

l

Display control characters in ASCII.

p

Display the line.

Input/Output Processing

e

Execute commands.

n

Skip current line and go to the next line.

r

Read another file's contents into the output stream.

R

Read one line from a file into the output.

w

Write input lines to another file.

W

Write first line in pattern space to another file.

q

Quit the sed script (no further output).

Q

Quit without printing the pattern space.

v

Require a specific version of GNU sed to run the script.

Yanking and Putting

h

Copy into hold space; wipe out what's there.

H

Copy into hold space; append to what's there.

g

Get the hold space back; wipe out the destination line.

G

Get the hold space back; append to the pattern space.

x

Exchange contents of the hold and pattern spaces.

Branching Commands

b

Branch to label or to end of script.

t

Same as b, but branch only after substitution.

T

Same ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required