Linux 指令篇:字符处理--tr(不直接对文件操作)

NAME
    tr - translate or delete characters

SYNOPSIS
    tr [OPTION]... SET1 [SET2]

DESCRIPTION
    Translate, squeeze, and/or delete characters from standard input, writing to standard output.

    -d, --delete
      delete characters in SET1, do not translate

================================================================================

e.g.

[root@localhost tmp]# tr 'ab' 'AB' <passwd
root:x:36:0:root:/root:/Bin/BAsh
Bin:x:62:1:Bin:/Bin:/sBin/nologin
dAemon:x:222:2:dAemon:/sBin:/sBin/nologin

 

[root@localhost tmp]# tr a-z A-Z <passwd
ROOT:X:36:0:ROOT:/ROOT:/BIN/BASH
BIN:X:62:1:BIN:/BIN:/SBIN/NOLOGIN
DAEMON:X:222:2:DAEMON:/SBIN:/SBIN/NOLOGIN

[root@localhost tmp]# tr -d ':' <passwd          /*重定向输入*/
rootx360root/root/bin/bash
binx621bin/bin/sbin/nologin
daemonx2222daemon/sbin/sbin/nologin

[root@localhost tmp]# cat passwd | tr -d ':'   /*管道命令*/
rootx360root/root/bin/bash
binx621bin/bin/sbin/nologin
daemonx2222daemon/sbin/sbin/nologin

 

posted @ 2014-04-24 10:58  CloudPing  阅读(244)  评论(0编辑  收藏  举报