本文共 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 $ |