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 .
SET1 represents the characters you want to translate or delete.
SET2 represents the characters to which you want to translate SET1.
Common options for the tr command include:
-c: Translate characters in SET1 to characters in SET2, but do not delete characters in SET1.
-d: Delete characters in SET1.
-s: Squeeze consecutive repeated characters into a single character.
-t: Translate characters in SET1 to characters in SET2, but only if SET1 has more characters than SET2.
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.