Tr (Unix)
From Wikipedia, the free encyclopedia
- The correct title of this article is tr. The initial letter is shown capitalized due to technical restrictions.
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. The following inputs, for instance, 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.)
Perl also has a tr operator, which operates analogously.
[edit] See also
[edit] External links
Unix command line programs (more) | |||
File and file system management: | cat | cd | chmod | chown | chgrp | cp | du | df | file | fsck | ln | ls | lsof | mkdir | more | mount | mv | pwd | rm | rmdir | split | touch | tree | ||
Process management: | anacron | at | chroot | crontab | kill | killall | nice | pgrep | pidof | pkill | ps | sleep | screen | time | timex | top | wait | ||
User Management/Environment: | env | finger | id | locale | mesg | passwd | su | sudo | uname | uptime | w | wall | who | whoami | write | ||
Text processing: | awk | cut | diff | ex | head | iconv | join | less | more | nkf | paste | sed | sort | tail | tr | uniq | wc | xargs | ||
Shell programming: | echo | expr | printf | unset | Printing: | lp |
Communications: inetd | netstat | ping | rlogin | traceroute |
Searching: find | grep | strings |
Miscellaneous: banner | bc | cal | man | size | yes |