tr 命令用法

  tr   

 a. 替换全部字符

  [root@bogon scripts]# tr [a-z] [A-Z]  < /etc/fstab    将读出的结果全部替换成大写字母  (取一行作为展示效果)

  UUID=9B81881D-A104-4EF9-A710-1D249ACAEEA3 /BOOT                   XFS     DEFAULTS        0 0

 b. 删除读出字符匹配范围内的全部字符    tr -d 'abc' < /etc/issue    ||  tr -d 'a-k' < /etc/issue

   [root@bogon scripts]# tr -d 'Kernel' < /etc/issue     效果展示

           \S
          \ o a \m

   原文件看下面

   [root@bogon scripts]# head -3 /etc/issue     与上面进行比对效果

          \S
          Kernel \r on an \m

  c. tr  -d 'a-z' < /path/to/file   用法示意

   [root@bogon scripts]# tr -d 'a-z' < /etc/issue   另一种效果展示

   \S
      K \ \

     D.  insert   tee 命令的用法  # cat /etc/issue | tee /tmp/issue.new | tr 'a-z' 'A-Z'   把第一个 cat 的结果 tee 命令保存至其它路径  然后把原来的内容传递给 tr 进行处理

   [root@bogon scripts]# cat /etc/issue | tee /tmp/issue.new | tr 'a-z' 'A-Z'

          \S
       
  KERNEL \R ON AN \M

 

posted @ 2018-04-07 20:26  超我  阅读(233)  评论(0编辑  收藏  举报