tr能转换或删除内容的操作

-s 替换

-d 删除

[root@monitor mj]# cat a
1234567890
[root@monitor mj]# cat a |tr '[0-9]' '[a-z]'
bcdefghija
[root@monitor mj]# cat a |tr -s '[0-9]' '[a-z]'
bcdefghija

[root@monitor mj]# cat b
MJ IS KING OF POP!
[root@monitor mj]# cat b|tr -s 'MJ' 'abcd'
ab IS KING OF POP!
 

[root@monitor mj]# cat c
0aaaa
[root@monitor mj]# cat c |tr -d '0'
aaaa
[root@monitor mj]# cat c
0aaaa

从例子能看出与sed的区别

补充:我们有时会遇到将windows系统下的文件拷贝到linux下使用的情况。

但由于两种系统的差异造成文件格式不一样;

[root@monitor mj]# vi -b dos.txt
sadasdasd^M
^M
^M
[root@monitor mj]# cat dos.txt |tr -d '\r'>c
[root@monitor mj]# cat c
sadasdasd


[root@monitor mj]#

这个例子就是将windows下的回车符“^M”替换为linux下的回车符“\r”

当然使用dos2unix也是可以的