The TR command does not accept specified file parameters, but only translates standard input. tr is short for translate, that is, translation. Note that it cannot translate sentences, only one character can be translated.
First, define the variable:
[[email protected]]#A=1,,2,,,3,,,4,,,5
The following example describes the command and its common options.
Example:
1. No option settings
[[email protected]]# echo $A | tr ‘,‘ ‘ ‘ 1 2 3 4 5 [[email protected]]# echo $A | tr [2-4] [b-d] 1,,b,,,c,,,d,,,5 [[email protected]]# echo $A | tr "23""bc" 1,,b,,,c,,,4,,,5
Note: here we will not replace the string, but Replace "2" with "B" and "3" with "C ".
Frequently used: lower case --> upper case
# tr [a-z] [A-Z]
2. Select "-s" to delete all recurring character sequences. Only the first string is retained, and the recurring string is compressed into a string.
[[email protected]]#echo $A | tr -s ‘,‘ 1,2,3,4,5 [[email protected]]#echo $A | tr -s ‘,‘ ‘ ‘ 12 3 4 5
3. Select "-d" to delete all input characters specified by the string.
[[email protected]]#echo $A | tr -d "23" 1,,,,,,,,4,,,5 [[email protected]]#echo $A | tr -d ‘,‘ 12345
Frequently used: Delete the '^ M' character in a Windows File
# tr -d"/r"
4. The option "-c" is used to replace the character set in the string. the character set must be a s c I.
[[email protected]]# echo $A | tr -c [1-5] ‘%’ 1%%2%%%3%%%4%%%5
This article is from the "Linux" blog, please be sure to keep this source http://4983206.blog.51cto.com/4973206/1438109