Tr (Unix)

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

The following inputs shift the input letters of the alphabet forward by seven characters.

$ echo cheer | tr abcdefghijklmnopqrstuvwxyz hijklmnopqrstuvwxyzabcdefg jolly

If your tr complies POSIX, you can simply replace the last two words with a-z h-za-g.

Translate " " to " ":

$ tr -A '12' '1512' < input1 > output1 $ tr -A '^M' '1512' < output1 > output2

Notice that not all versions of tr support -A option. And also, you do not want to use double quotes, instead of single quotes, because they could make your shell evaluate backslashes between them. Notice , 12 and ^M being representations of a line feed in "character escape code", "ASCII octal" and "caret notation", respectively; and 15 being representations of a carriage return. For background on the need for this translation, see "newline".

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

$ echo "ibm 9000" >computer.txt $ tr a-z za-y 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] " 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.

ee also

*Sed
*List of Unix programs

External links

* [http://www.linfo.org/tr.html The tr Command] - by The Linux Information Project (LINFO)
* [http://www.linuxmanpages.com/man1/tr.1.php] The program's manpage
* [http://www.softpanorama.org/Tools/tr.shtml] Softpanorama tr page


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Tr (Unix) — tr est une commande Unix qui permet de transposer ou d éliminer des caractères dans un fichier ou un flux de données. Exemples : Pour remplacer les minuscules par les majuscules correspondantes tr [a z] [A Z] < fichier Pour remplacer n… …   Wikipédia en Français

  • Tr (unix) — tr est une commande Unix qui permet de transposer ou d éliminer des caractères dans un fichier ou un flux de données. Exemples : Pour remplacer les minuscules par les majuscules correspondantes tr [a z] [A Z] < fichier Pour remplacer n… …   Wikipédia en Français

  • tr (Unix) — tr est une commande Unix qui permet de transposer ou d éliminer des caractères dans un fichier ou un flux de données. Exemples : Pour remplacer les minuscules par les majuscules correspondantes tr [a z] [A Z] < fichier Pour remplacer n… …   Wikipédia en Français

  • Tr — UNIX утилита для преобразования символов. Утилита tr копирует стандартный входной поток в стандартный выходной, подставляя или удаляя некоторые символы. Заданные опции и операнды строка1 и строка2 управляют происходящим преобразованием по ходу… …   Википедия

  • Tr (значения) — Tr, TR  аббревиатура: Официальные коды ISO 3166 1 alpha 2 код Турции ISO 639 1 alpha 2 код турецкого языка В науке и технике Tr  UNIX утилита для преобразования символов След матрицы (от англ. trace  «след») Tr1 товарный… …   Википедия

  • tr — У этого термина существуют и другие значения, см. Tr (значения). tr UNIX утилита для преобразования символов. Утилита tr копирует стандартный входной поток в стандартный выходной, подставляя или удаляя некоторые символы. Заданные опции и операнды …   Википедия

  • UNIX-Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Befehle — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Kommando — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”