tr命令
功能:将标准输入输入的字符串转换为指定字符串,然后输出到标准输出
用法:Usage: tr [OPTION]… SET1 [SET2]
比如:
[root@redhatclient ~]# echo abc |tr a A
Abc
将字符a替换为大写的A
[root@redhatclient ~]# echo abc |tr ab AB
ABc
[root@redhatclient ~]#
可以跟的参数:
[root@redhatclient ~]# tr --help
Usage: tr [OPTION]... SET1 [SET2]
Translate, squeeze, and/or delete characters from standard input,
writing to standard output.
-c, -C, --complement use the complement of SET1
-d, --delete delete characters in SET1, do not translate
-s, --squeeze-repeats replace each input sequence of a repeated character
that is listed in SET1 with a single occurrence
of that character
-t, --truncate-set1 first truncate SET1 to length of SET2
--help display this help and exit
--version output version information and exit
-c 代表将标准输入中不是set1的字符改为set2
[root@redhatclient ~]# echo abaaaaaaaacAAAcde |tr -c a A
aAaaaaaaaaAAAAAAAA
-d代表删除set1
[root@redhatclient ~]# echo abaaaaaaaacAAAcde |tr -d a
bcAAAcde
-s代表如果set1有相邻重复的,则只保留一个
[root@redhatclient ~]# echo abaaaaaaaacAAAcde |tr -s a
abacAAAcde
[root@redhatclient ~]#
“`