Tr command for shell learning
The tr command does not accept the specified file parameters, but only translates the standard input. Tr is the abbreviation of translate, that is, translation. It should be noted that it cannot translate sentences, only a single character.
First, define the variable:
[root@tong] # Achievement 1, pause 2, 3, 3, 4, 5
The following is an example of this command and its common options.
Example:
1. No option setting
[root@tong] # echo $A | tr','1 23 4 5 [root@tong] # echo $A | tr [2-4] [blightd] 1 tr [root@tong] # echo $A | tr "23"bc" 1 mineforce5 [root@tong] # echo $A | tr "23"bc" 1
Note that instead of replacing the string, replace "2" with "b" and "3" with "c".
Commonly used: lowercase-> uppercase
# tr [Amurz] [Amurz]
two。 The option "- s" removes all recurring character sequences, leaving only the first, that is, the recurring string is compressed into a single string.
[root@tong] # echo $A | tr-s','1 root@tong 2 echo 3 recorder 4 [root@tong] # echo $A | tr-s','12 3 4 5
3. Option "- d" to delete all input characters specified by the string.
[root@tong] # echo $A | tr-d "23" 1 tr 4 [root@tong] # echo $A | tr-d', '12345
Commonly used: delete'^ M 'characters from Windows files
# tr-d "/ r"
4. Option "- c" to replace the complement of the character set in the string, requiring the character set to be A S C I I.
[root@tong] # echo $A | tr-c [1-5]'%'1%% 2%% 3%% 4%% 5