欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

[20191106]善用column格式化输出.txt

程序员文章站 2022-04-10 14:31:02
[20191106]善用column格式化输出.txt# man columnDESCRIPTION The column utility formats its input into multiple columns. Rows are filled before columns. Input i ......

[20191106]善用column格式化输出.txt

# man column
description
     the column utility formats its input into multiple columns.  rows are filled before columns.  input is taken from
     file operands, or, by default, from the standard input.  empty lines are ignored.

     -t      determine the number of columns the input contains and create a table.  columns are delimited with
             whitespace, by default, or with the characters supplied using the -s option.  useful for pretty-printing
             displays.

--//可以利用格式化输出获得好的显示效果,例子如下:

$ mount
/dev/sda1 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda2 on /tmp type ext4 (rw)
/dev/sda5 on /u01 type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

--//mount的显示连接在一起,不好查看.而假如column -t
$ mount | column -t
/dev/sda1  on  /                         type  ext4         (rw)
proc       on  /proc                     type  proc         (rw)
sysfs      on  /sys                      type  sysfs        (rw)
devpts     on  /dev/pts                  type  devpts       (rw,gid=5,mode=620)
tmpfs      on  /dev/shm                  type  tmpfs        (rw)
/dev/sda2  on  /tmp                      type  ext4         (rw)
/dev/sda5  on  /u01                      type  ext4         (rw)
none       on  /proc/sys/fs/binfmt_misc  type  binfmt_misc  (rw)

--//这样就好看了.再比如:
# ss -nop
--//显示太宽了.不贴出结果.而加入column -t过滤,显示如下:

# ss -nop | column -t
state  recv-q  send-q  local                 address:port          peer                         address:port
estab  0       0       192.168.100.78:1521   192.168.100.78:23591  timer:(keepalive,4.213ms,0)  users:(("tnslsnr",29630,12))
estab  0       0       192.168.100.78:23591  192.168.100.78:1521   users:(("oracle",54271,10))
estab  0       44      192.168.100.78:22     192.168.98.6:53411    timer:(on,402ms,0)           users:(("sshd",45671,3))
estab  0       0       192.168.100.78:12260  192.168.100.78:1521   users:(("oracle",57162,10))
estab  0       0       192.168.100.78:22     192.168.98.6:51190    timer:(keepalive,50sec,0)    users:(("sshd",45348,3))
estab  0       0       192.168.100.78:1521   192.168.100.78:12260  timer:(keepalive,33sec,0)    users:(("tnslsnr",29630,13))

--//这样就好看许多.