tr(translate的缩写)主要用于字符的删除与替换

语法:tr[-c/d/s/t] [SET1] [SET2]

参数:-c:(complement)用SET2中的字符替换SET1中没出现的字符

     -d:(delete)删除SET1中的所有字符

     -s:(sequence repreat)压缩SET1中重复的字符,使其只出现一次

     -t:将SET1转换为SET2(为缺省状态)

案例分析:

-c——用SET2中的字符替换SET1中没出现的字符。eg:

        shell   tr用法

        最后friend后面的字符也被替换成了“*”说明字符串最后会自动添上“\0"的。

-d——删除SET1中的所有字符

        shell   tr用法

 -s——压缩SET1中连续重复的字符,使其只出现一次

        shell   tr用法

-t——将SET1转换为SET2(为缺省状态)

        shell   tr用法

把文本中的所有逗号改为回车

cat aa|tr ',' '\n'

 

 

相关文章:

  • 2021-09-29
  • 2021-12-07
  • 2022-12-23
  • 2021-08-11
  • 2021-05-29
  • 2021-12-17
  • 2021-06-11
  • 2021-06-11
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案