Полезная информация

sed & awk

sed & awkSearch this book
Previous: 5.6 ListChapter 5
Basic sed Commands
Next: 5.8 Print
 

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.[9] Its syntax follows:

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


Previous: 5.6 Listsed & awkNext: 5.8 Print
5.6 ListBook Index5.8 Print

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System