Linux-字符替换tr

7.Shell

本章同步视频:https://edu.51cto.com/sd/e4874

7.6.5 字符转换与链接命令: tr, join, paste

1.tr - translate or delete characterside

(1)语法google

[dmtsai@study ~]$ tr [-ds] SET1 ...spa

选项与参数:orm

-d  :删除讯息当中的 SET1 这个字符串;视频

-s  :取代掉重复的字符!字符串

(2)用法get

[root@localhost tmp]# cat tr.file 同步

google 110 5140it

[root@localhost tmp]# cat tr.file |tr "o" "O"ast

gOOgle 110 5140       #将o替换为O

[root@localhost tmp]# cat tr.file |tr "[a-z]" "[A-Z]"

GOOGLE 110 5140    #小写变大写

[root@localhost tmp]# cat tr.file |tr [0-9] [a-j]

google bba fbea    #数字0-9用字码a-j替换

[root@localhost tmp]# cat tr.file |tr -d " "

google1105140     #删除空格

[root@localhost tmp]# cat tr.file |tr -s [a-zA-Z0-9]

gogle 10 5140     #去掉连续的字母和数字

[root@localhost tmp]# cat tr.file |tr -s "\n"

google 110 5140     #删除空行,即连续的回车

[root@localhost tmp]# cat tr.file |tr " " ":"

google:110:5140    #用:作分隔符,而再也不用空格

本章同步视频:https://edu.51cto.com/sd/e4874

相关文章
相关标签/搜索