1. 程式人生 > >tr 命令用法

tr 命令用法

path kernel cat log iss new 替換 大寫字母 tmp

  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

tr 命令用法