The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

tr - Character Translation and Deletion





The tr (translate or delete characters) command is used to translate or delete characters in a text stream. It allows you to perform basic character-level transformations on text.

The syntax of the tr command is as follows:
tr [OPTIONS] SET1 SET2 .

Common options for the tr command include:

Here are some examples of using the tr command:

$ echo 'google' | tr 'g' 'G' ←Translate lowercase 'g' to uppercase 'G'
GooGle
$ echo 'google' | tr -d 'o' ←Delete all lowercase 'o' characters
ggle
cat file1 | tr 'a-z' 'A-Z' > file2 ←Convert the contents of "file1" to uppercase and save it as "file2"
$ cat FILE.txt | tr '[:upper:]' '[:lower:]' ←Convert all uppercase letters to lowercase

For more options, examples, and detailed explanations of the tr command, please refer to the provided link.