[Chapter 34] 34.12 Transformations on Text
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:47:19Z

#

| Chapter 34 The sed Stream Editor |

## 34.12 Transformations on Text

The transform command (y) is useful for exchanging lowercase letters for uppercase letters on a line. Effectively, it performs a similar function to tr (35.11). It replaces any character found in the first string with the equivalent character in the second string. The command:

>     y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/

will convert any lowercase letter into the corresponding uppercase letter. The following:

>     y/abcdefghijklmnopqrstuvwxyz/nopqrstuvwxyzabcdefghijklm/

would perform a rot13 transformation - a simple form of encryption in which each alphabetic character is replaced by the character halfway through the alphabet. (rot13 encryption is sometimes used to keep offensive news postings (1.33) from being read except by someone who really means to. Encryption and decryption are automatically supported by most news readers, but it's fun to see how simple the encryption is. By the way, the command above handles only lowercase letters; if we'd shown uppercase as well, the command would have run past the margins!)

- TOR

34.11 Search & Replacement: One Match Among Many |  | 34.13 Hold Space: The Set-Aside Buffer