作用:從標準輸入中替換,縮減或者刪除字符linux常用命令,并將結(jié)果輸出到標準輸出
格式:tr [option] [set1] [set2]
tr [選項] [字符1] [字符2]
把y替換m, o替換elinux常用命令,并不僅僅是yo替換me
ghostwu@dev:~/linux/tr$ cat ghostwu.txt hello,my name is ghostwu, my qq is 359173352@qq.com my blog is http://www.cnblogs.com/ghostwu nice to meet you, feel free to contact me. ghostwu@dev:~/linux/tr$ tr 'me' 'yo' < ghostwu.txt hollo,yy nayo is ghostwu, yy qq is 359173352@qq.coy yy blog is http://www.cnblogs.coy/ghostwu nico to yoot you, fool froo to contact yo.
小寫字母變成大寫
ghostwu@dev:~/linux/tr$ tr '[a-z]' '[A-Z]' < ghostwu.txt HELLO,MY NAME IS GHOSTWU, MY QQ IS 359173352@QQ.COM MY BLOG IS HTTP://WWW.CNBLOGS.COM/GHOSTWU NICE TO MEET YOU, FEEL FREE TO CONTACT ME.
-d: 刪除. 刪除數(shù)字
ghostwu@dev:~/linux/tr$ tr -d '[0-9]' < ghostwu.txt hello,my name is ghostwu, my qq is @qq.com my blog is http://www.cnblogs.com/ghostwu nice to meet you, feel free to contact me.
刪除a, b, c中出現(xiàn)的任意一個字母
ghostwu@dev:~/linux/tr$ tr -d ['a-c'] < ghostwu.txt hello,my nme is ghostwu, my qq is 359173352@qq.om my log is http://www.nlogs.om/ghostwu nie to meet you, feel free to ontt me.
刪除文件中的換行符
ghostwu@dev:~/linux/tr$ tr -d '\n' < ghostwu.txt hello,my name is ghostwu,my qq is 359173352@qq.commy blog is http://www.cnblogs.com/ghostwunice to meet you,feel free to contact me.
-s:保留連續(xù)字符的第一個,其他的刪除。 壓縮連續(xù)字符
ghostwu@dev:~/linux/tr$ echo 'gggghhostwwwu' | tr -s ghostwu ghostwu
-c:取反。 把所有的非數(shù)字都變成#
上一個教程:Linux 常見命令
下一個教程:LINUX:alias命令詳解