O'Reilly logo

Linux in a Nutshell, 6th Edition by Robert Love, Stephen Figgins, Ellen Siever, 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

Name

s

Synopsis

[address1[,address2]]s/pattern/replacement/[flags]

Substitute replacement for pattern on each addressed line. If pattern addresses are used, the pattern // represents the last pattern address specified. Any delimiter may be used. Use \ within pattern or replacement to escape the delimiter. The following flags can be specified (those marked with a † are specific to GNU sed):

n

Replace nth instance of pattern on each addressed line. n is any number in the range 1 to 512, and the default is 1.

e

If the substitution was made, execute the contents of the pattern space as a shell command and replaces the pattern space with the results.

g

Replace all instances of pattern on each addressed line, not just the first instance.

i or I

Do a case-insensitive regular expression match.

m or M

Allow ^ and $ to match around a newline embedded in the pattern space.

p

Print the line if the substitution is successful. If several successful substitutions are successful, sed prints multiple copies of the line.

w file

Write the line to file if a replacement was done. In the traditional Unix sed, a maximum of 10 different files can be opened.

GNU sed allows you to use the special filenames /dev/stdout and /dev/stderr to write to standard output or standard error, respectively.

Within the replacement, GNU sed accepts special escape sequences, with the following meanings:

\L

Lowercase the replacement text until a terminating \E or \U.

\l

Lowercase the following character only.

\U

Uppercase the replacement text ...

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