commands

tr — translate or delete characters

Translate characters from stdin to stdout; -d deletes selected characters, -s squeezes repeats. No filename operand. GNU tr has multibyte limitations; use C locale for ASCII fixtures. Example assumes a fresh text-streams lab fixture.

Formal Syntax & Structure

linux syntaxlinux
tr [OPTION]... STRING1 [STRING2]

Parameters & Attributes

NameTypeDescription
STRING1operandFirst character array specification; not an arbitrary regular expression.
STRING2operandSecond array, required for translation and for -ds; omit for delete-only or single-array squeeze.
-doptionDelete characters in first array; do not translate.
-soptionSqueeze consecutive occurrences of characters in the last specified array.

Return Value

exit status and output

GNU tr transforms stdin into stdout and returns nonzero on read/write or option errors. No matching characters is a successful unchanged result, not a no-match status.

Working Example

Example Snippetlinux
LC_ALL=C tr '[:lower:]' '[:upper:]' < names.txt
Linux Reference