BookRags.com Literature Guides Literature
Guides
Criticism & Essays Criticism &
Essays
Questions & Answers Questions &
Answers
Lesson Plans Lesson
Plans
My Bibliography Periodic Table U.S. Presidents Shakespeare Sonnet Shake-Up
Research Anything:        
History | Encyclopedias | Films | News | Create a Bibliography | More... Login | Register | Help
Not What You Meant?  There are 30 definitions for TR.

Tr (Unix)

Print-Friendly
About 2 pages (504 words)

Bookmark and Share Questions on this topic? Just ask!

tr (abbreviated from translate or transliterate) is a command in Unix-like operating systems. When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set.

Examples

Translate "\n" to "\r\n":

$ tr -A "\12" "\15\12" < input1  > output1
$ tr -A "^M" "\15\12"  < output1 > output2

The following inputs shift the input letters of the alphabet back by one character.

$ echo "ibm 9000" >computer.txt
$ tr a-z za-y <computer.txt
hal 9000

In some older versions of tr (not POSIX-compliant), the character ranges must be enclosed in brackets, which must then be quoted against interpretation by the shell:

$ tr "[a-z]" "z[a-y]" <computer.txt

If it's not known in advance which variant of tr is being invoked, then in this example one would have to write the ranges in unabbreviated form (tr abcdefghijklmnopqrstuvwxyz zabcdefghijklmnopqrstuvwxy). For some applications, a single invocation is portable despite containing ranges: ROT13 can be portably implemented as tr "[A-M][N-Z][a-m][n-z]" "[N-Z][A-M][n-z][a-m]". (This works because the brackets, which are not part of the range syntax in POSIX tr, align properly in the two strings, and hence will be safely interpreted as a request to map the bracket character to itself.) Ruby and Perl also have an internal tr operator, which operates analogously.

See also

External links

View More Summaries on Tr (Unix)
 
Ask any question on Tr (Unix) and get it answered FAST!
Answer questions in BookRags Q&A and earn points toward
discounted or even FREE Study Guides and other BookRags products!
Learn more about BookRags Q&A
Copyrights
Tr (Unix) from Wíkipedia. ©2006 by Wíkipedia. Licensed under the GNU Free Documentation License. View a list of authors or edit this article.

Article Navigation
Join BookRagslearn moreJoin BookRags




About BookRags | Customer Service | Report an Error | Terms of Use | Privacy Policy