字符转换指令tr,col,expand

tr -[dsx] seting ...

使用tr替换字符:

1
2
3
4
5
6
7
8
9
10
11
12
[whx@localhost ~]$ last |  head  -n 5 |  tr '[a-z]'  '[A-Z]'
WHX     PTS /0         192.168.21.1     SUN AUG 27 18:22   STILL LOGGED IN  
REBOOT  SYSTEM BOOT  2.6.32-696.EL6.X SUNAUG 27 18:21 - 00:39  (06:18)   
WHX     PTS /0         192.168.21.1     THU AUG 24 18:37 - 02:54  (08:17)   
WHX     TTY1         :0               THU AUG 24 18:36 - DOWN   (08:18)   
REBOOT  SYSTEM BOOT  2.6.32-696.EL6.X THUAUG 24 18:35 - 02:55  (08:19)   
[whx@localhost ~]$ last |  head  -n 5
whx     pts /0         192.168.21.1     Sun Aug 27 18:22   still logged  in  
reboot  system boot  2.6.32-696.el6.x SunAug 27 18:21 - 00:39  (06:18)   
whx     pts /0         192.168.21.1     Thu Aug 24 18:37 - 02:54  (08:17)   
whx     tty1         :0               Thu Aug 24 18:36 - down   (08:18)   
reboot  system boot  2.6.32-696.el6.x ThuAug 24 18:35 - 02:55  (08:19)

 

添加-d参数删除字符:

1
2
3
4
5
6
7
8
9
10
11
12
[whx@localhost ~]$  cat  /etc/passwd  | head  -n5
root:x:0:0:root: /root : /bin/bash
bin:x:1:1:bin: /bin : /sbin/nologin
daemon:x:2:2:daemon: /sbin : /sbin/nologin
adm:x:3:4:adm: /var/adm : /sbin/nologin
lp:x:4:7:lp: /var/spool/lpd : /sbin/nologin
[whx@localhost ~]$  cat  /etc/passwd  | head  -n5 | tr  -d  ':'
rootx00root /root/bin/bash
binx11bin /bin/sbin/nologin
daemonx22daemon /sbin/sbin/nologin
admx34adm /var/adm/sbin/nologin
lpx47lp /var/spool/lpd/sbin/nologin

 

添加-s参数去除重复字符:

1
2
[whx@localhost ~]$  echo  'thissss   issss aaaa test' | tr  -s  'sa'
this  is a   test

 

col常用于将man page转存为纯文本文件以方便查阅。

col -x 将tab替换成对等的空格键

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[whx@localhost ~]$  cat   /etc/man .config |  tail  -10 | col -x | cat  -A| tail  -10
#$
# Enable/disable makewhatis database cronupdates.$
# If MAKEWHATISDBUPDATES variable isuncommented$
# and set to n or N, cron scripts$
# /etc/cron.daily/makewhatis.cron$
# /etc/cron.weekly/makewhatis.cron$
# will not update makewhatis database.$
# Otherwise the database will be updated.$
#$
#MAKEWHATISDBUPDATES    n$
[whx@localhost ~]$  cat   /etc/man .config |  tail  -10 |  cat  -A
#$
# Enable/disable makewhatis database cronupdates.$
# If MAKEWHATISDBUPDATES variable isuncommented$
# and set to n or N, cron scripts $
# /etc/cron.daily/makewhatis.cron$
# /etc/cron.weekly/makewhatis.cron$
# will not update makewhatis database.$
# Otherwise the database will be updated.$
# $
#MAKEWHATISDBUPDATES^In$

 

expand转换指令:

expand  [-t] file 

使用-t参数设置使用6个空格键代替tab键(默认使用8个空格键代替tab键)

1
2
3
4
5
6
7
8
[whx@localhost ~]$  grep  '^MANPATH' /etc/man .config | head  -n 3 |  expand  -t 6 | cat  -A
MANPATH     /usr/man $
MANPATH     /usr/share/man $
MANPATH     /usr/local/man $
[whx@localhost ~]$  grep  '^MANPATH' /etc/man .config | head  -n 3 |  cat  -A
MANPATH^I /usr/man $
MANPATH^I /usr/share/man $
MANPATH^I /usr/local/man $



本文转自 天黑顺路 51CTO博客,原文链接:http://blog.51cto.com/mjal01/1960194,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值