用于讲一种stdin转换成另一种格式输出
tr set1 set2 #将set1中内容替换成set2集合中对应字符
set2比set1短,会自动扩张和set1一样,用最后一个元素填充
set1短,会忽略set2多出的元素
-d 删除指定集合元素,只有set1参数
echo "Hello 123 world 456" | tr -d '0-9' #Hello world
-c 补集(Complementing),影响set1d的解释,-c后会使用不包含set1中的元素映射
echo "123abc123" | tr -c '0-9\n' ' ' #输出123 123
-s 压缩(Squeezing) 字符,将多个相同字符合并成一个
echo "GNU is not UNIX." | tr -s ' '
#GNU is not UNIX.
字符集使用:
alnum: Alphanumeric characters
f alpha: Alphabetic characters
f cntrl: Control (non-printing) characters
f digit: Numeric characters
f graph: Graphic characters
f lower: Lower-case alphabetic characters
f print: Printable characters
f punct: Punctuation characters
f space: Whitespace characters
f upper: Upper-case characters
f xdigit: Hexadecimal characters
echo "aaabbb111" | tr [:lower:] [:upper:] #AAABBB111