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

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 n th 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 replace 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 successive substitutions are successful, sed prints multiple copies of the line.

w file

Write the line to file if a replacement was done. In 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 ...

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