博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符转换指令tr,col,expand
阅读量:6936 次
发布时间:2019-06-27

本文共 2682 字,大约阅读时间需要 8 分钟。

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,如需转载请自行联系原作者
你可能感兴趣的文章
zabbix 监控硬盘状态
查看>>
关于Cpp中的extern
查看>>
APUE读书笔记-14高级输入输出-07readv和writev函数
查看>>
关于Linux的内存(free -m)
查看>>
修改linux系统配置文件 /etc/inittab 默认从字符界面启动系统
查看>>
Servlet过滤器和监听器知识总结
查看>>
Android(杂项)
查看>>
vSphere之安装VMware ESXi 6
查看>>
MyEclipse定位class文件
查看>>
一个用于监控Dell PowerEdge服务器硬件状态的nagios/icinga插件
查看>>
我的友情链接
查看>>
Xshell连接Ubuntu
查看>>
进阶之初探nodeJS
查看>>
Mac OS X添加网络打印机
查看>>
五个典型的JavaScript面试题
查看>>
如何搭建搭建各个版本的openstack的本地yum源?
查看>>
CentOS6.8下搭建Ipsec+L2TP ***服务
查看>>
linux基本命令
查看>>
mysql主从延迟
查看>>
不在让你为你写代码头疼的链接页代码
查看>>