It is said that the TR command is a fine gadget at the home of the Linux line, and can be used to write many graceful single-line commands. Use: Tr-c-d-s ["String1_to_translate_from"] ["string2_to_translate_to"] parameter:-c #使用string1的补集, request string for ascii-d # Delete all input characters in string1-s #删除所有重复出现的字符序列, only the first one, the string to be repeated will be compressed into the first string
#大小转为小写
> echo "Hello World" |tr "A-Z" "A-Z"
Hello World
#删除数字
> echo "Hello 134 World 565" |tr-d "1- 9 "
Hello World
#-c", representing the deletion of non-numeric, ' \ n ' linefeed
> Echo ' Hello 134 World 565 ' |tr-d-C ' 1-9\n '
134565
#删除非数字 , spaces, ' \ n ' linefeed
> Echo ' Hello 134 World 565 ' |tr-d-c ' 1-9 \ n '
134 565
#压缩空格, only one
> echo "Hello World" Hello shell "|tr-s" Hello World
Hello Shell
#用tr命令做加法
> Cat sum.txt
1
2
3
4< C20/>5
> Cat sum.txt |echo $[$ (tr ' \ n ' + ') 0]
#cat sum.txt|tr ' \ n ' + ' replace all ' \ n ' with a ' + ', output 1+2+3+4+5+ , and finally a 0 becomes $[1+2+3+4+5+0] gets the
character class: TR can also use character classes, as
follows alnum
#字母和数字 Alpha #字母
Cntrl The #控制 (nonprinting) character
digit #数字
graph #图形
lower #小写字母
Upper #大写字母
Print #可打印字符
punct #标点符号
space #空白字符
xdigit #十六进制字符
>tr ' [: Lower:] ' [: Upper:] '
lowercase to uppercase