tr命令

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 ~]# 

“`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值