home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


sed & awksed & awkSearch this book

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:

[35]This command is patterned after the UNIX tr command, which translates characters. This is a useful command in its own right; see your local documentation for details. Undoubtedly sed's y command would have been named t, if t had not already been taken (by the test command, see Chapter 6, "Advanced sed Commands").

[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.)



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.