名称:tr
位置:/usr/bin/tr
权限:所有用户
作用:可以用来删除一段信息中的文字、或者进行文字信息的替换
用法:tr [OPTION]... SET1 [SET2]
选项:
-d 删除信息当中的SET1这个字符串
-s 替换掉重复的字符串
例1:
tr在没有任何参数选项时,默认是替换,与加上-s参数选项结果是一致的。
$ last| tr "[a-z]" "[A-Z]"|sed -n '1,5p' CWJY1202 PTS/0 :0 SAT JAN 10 22:14 STILL LOGGED IN REBOOT SYSTEM BOOT 3.2.0-24-GENERIC SAT JAN 10 21:45 - 23:48 (02:03) CWJY1202 PTS/0 :0.0 SAT JAN 10 19:24 - DOWN (00:00) REBOOT SYSTEM BOOT 3.2.0-24-GENERIC SAT JAN 10 14:17 - 19:24 (05:07) REBOOT SYSTEM BOOT 3.2.0-24-GENERIC FRI JAN 9 20:50 - 22:50 (01:59)
$ last| tr -s "[a-z]" "[A-Z]"|sed -n '1,5p' CWJY1202 PTS/0 :0 SAT JAN 10 22:14 STIL LOGED IN REBOT SYSTEM BOT 3.2.0-24-GENERIC SAT JAN 10 21:45 - 23:51 (02:05) CWJY1202 PTS/0 :0.0 SAT JAN 10 19:24 - DOWN (00:00) REBOT SYSTEM BOT 3.2.0-24-GENERIC SAT JAN 10 14:17 - 19:24 (05:07) REBOT SYSTEM BOT 3.2.0-24-GENERIC FRI JAN 9 20:50 - 22:50 (01:59)
注意:SET1 和SET2要加引号,单引号和双引号都可以
$ cat a pa:11:a sa:32:c app:5:b stort:1:d pear:4:aa hello:3:f $ cat a| tr -d "[0-9]" pa::a sa::c app::b stort::d pear::aa hello::f
待续……
原文地址:http://blog.csdn.net/u011402596/article/details/42592703