Replacement Patterns

The characters in the following table have special meaning only in replacement patterns, used for example in editing, when searching for and replacing text.

Character

Pattern

\

Turn off the special meaning of the following character.

\n

Reuse the text matched by the nth subpattern previously saved by \( and \) as part of the replacement pattern. n is a number from 1 to 9, with 1 starting on the left.

&

Reuse the text matched by the search pattern as part of the replacement pattern.

~

Reuse the previous replacement pattern in the current replacement pattern. Must be the only character in the replacement pattern (ex and vi).

%

Reuse the previous replacement pattern in the current replacement pattern. Must be the only character in the replacement pattern (ed).

\u

Convert the first character of replacement pattern to uppercase.

\U

Convert the entire replacement pattern to uppercase.

\l

Convert the first character of replacement pattern to lowercase.

\L

Convert the entire replacement pattern to lowercase.

\e

Turn off previous \u or \l.

\E

Turn off previous \U or \L.

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.