5.7. Transform
The transform command is peculiar, not only because it is the least
mnemonic of all sed commands. This command transforms each character
by position in string abc to its equivalent in
string xyz.[35]
Its syntax follows:
[address]y/abc/xyz/
The replacement is made by character position. Therefore, it has no
idea of a "word." Thus, "a" is replaced by "x" anywhere on the line,
regardless of whether or not it is followed by a "b". One possible
use of this command is to replace lowercase letters with their
uppercase counterparts.
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
This command affects the entire contents of the pattern space. If you
want to convert a single word on the input line, you could do it by
using the hold space. See Chapter 6, "Advanced sed
Commands"
for more details on how to
use the hold space. (The process is not trivial: you output the line
up to the word you want to change, delete that portion of the line,
copy the line after the word to the hold space, transform the word,
and then append the contents of the hold space back to the pattern
space.)
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|