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

相關文章
相關標籤/搜索