echo 12345 | tr ‘0-9’ ‘9876543210’
echo “Hello 123 world 456” | tr -d ‘0-9’
Hello world
echo hello 1 char 2 next 4 | tr -d -c ‘0-9 \n’
1 2 4
-d 删除
-c 补集
tr 的 -s 选项可以压缩输入中重复的字符,方法如下:
$ echo “GNU is not UNIX. Recursive right ?” | tr -s ’ ’
GNU is not UNIX. Recursive right ?
$ cat sum.txt
1
2
3
4
5
catsum.txt|echo
[
(tr‘\n′‘+′)0]15
[ operation ] 执行算术运算,因此得到下面的字符串:
echo $[ 1+2+3+4+5+0 ]
tr ‘[:lower:]’ ‘[:upper:]’