34.13. Transformations on TextThe transform command (y) is useful for exchanging lowercase letters for uppercase letters on a line. Effectively, it performs a similar function to tr (Section 21.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 (or comical) news postings (Section 1.21) from being read except by someone who really means to (such as if you have read the joke and now want to read the punch line). 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 Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|