Linux-字符替換tr

7.Shell

本章同步視頻:https://edu.51cto.com/sd/e4874

7.6.5 字符轉換與連接命令: tr, join, paste

1.tr - translate or delete characters

(1)語法

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

選項與參數:

-d  :刪除訊息當中的 SET1 這個字符串;

-s  :取代掉重複的字符!

(2)用法

[root@localhost tmp]# cat tr.file

google 110 5140

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

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章