Linux tr 命令


tr主要替换字符.
替换字符

[root@myserver test]# cat aaa 
asdsad
asdasd
asdasd
asdasd

[root@myserver test]# cat aaa | tr '\n' ','
asdsad,asdasd,asdasd,asdasd,[root@myserver test]# 

删除字符

[root@myserver test]# cat aaa 
asdsad
asdasd
asdasd
asdasd

[root@myserver test]# cat aaa | tr -d 'a'
sdsd
sdsd
sdsd
sdsd
[root@myserver test]# 

匹配删除

[root@myserver test]# cat aaa 
aaasdfgh
aaasdfgh
aaasdfgh
aaasdfgh

[root@myserver test]# cat aaa | tr -s 'a' 'b'
bsdfgh
bsdfgh
bsdfgh
bsdfgh

[root@myserver test]# cat aaa | tr -s 'a' 'aa'
asdfgh
asdfgh
asdfgh
asdfgh
分享:

评论