tldr/pages/common/tr.md
Angsuman Chakraborty fc6b0e4661
Corrected the example: Compress a series of identical characters to a single character
The example wrongly used \n instead of {{input_characters}}.
2017-11-26 16:09:41 +05:30

789 B

tr

Translate characters - run replacements based on single characters and character sets.

  • Replace all occurrences of a character in a file, and print the result:

tr {{find_characters}} {{replace_characters}} < {{filename}}

  • Map each character of the first set to the corresponding character of the second set:

tr 'abcd' 'jkmn' < {{filename}}

  • Delete all occurrences of the specified set of characters from the input:

tr -d '{{input_characters}}'

  • Compress a series of identical characters to a single character:

tr -s '{{input_characters}}'

  • Translate the contents of the file to upper-case and print result:

tr "[:lower:]" "[:upper:]" < {{filename}}

  • Strip out non-printable characters from the file and print result:

tr -cd "[:print:]" < {{filename}}