tr 命令

时间:2023-03-09 19:43:51
tr 命令

tr命令常用来替换,

tr命令可以对来自标准输入的字符进行替换、压缩和删除。它可以将一组字符变成另一组字符,经常用来编写优美的单行命令,作用很强大

-d, –delete  删除指定的字符, 比如  echo "i2i3ii0i3i4i9i" | tr -d [0-9], 删除字符串中所有的数字,最后输出 “iiiiiiii”

-d

[root@localhost sh~]# cat test.txt
"helo"
[root@localhost sh]# cat test.txt |tr -d '"'
helo

删除a-zA-Z的字符,还有: ,""字符

tr -d "a-zA-Z,:\""
[root@localhost sh]# cat .txt
abcdefg [root@localhost sh]# cat .txt |tr [a-z] [A-Z]
ABCDEFG // 把文件小写字母变成大写字母

root@H5_521_YUNWEI_119.146.201.90 15:52:49~]# cat test.txt "helo"[root@H5_521_YUNWEI_119.146.201.90 15:52:51~]# cat test.txt |tr -d """> ^C[root@H5_521_YUNWEI_119.146.201.90 15:53:01~]# cat test.txt |tr -d '"'helo