(转)[小工具] Linux下列格式化工具

当你看到Linux下命令输出的列歪歪扭扭时,是不是看着很不爽?column 命令就可以方便地解决这个问题。

比如:

我们一般就只用到上面这一个用法。

column的其他用法如下:

选项
含义
-c 字符数 指定显示的列宽
-s“ 分隔符 “ 使用-t选项时,指定分隔符(允许指定多个分隔符)
-t 判断输入行的列数来创建一个表。分隔符是使用在-s中指定的字符。如果没有指定分隔符,默认是空格
-x 更改排列顺序(左→右)。默认的顺序为(上→下)

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@uyhd000225 ~]# mount
/dev/hda1 on / type ext3 (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/xvdb1 on /data type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@uyhd000225 ~]# mount |column -t
/dev/hda1   on  /                         type  ext3         (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/xvdb1  on  /data                     type  ext3         (rw)
none        on  /proc/sys/fs/binfmt_misc  type  binfmt_misc  (rw)

解释-s选项:

我以为-s选项是输出分隔符,比如上面,我是用如下命令:

1
2
3
4
5
6
7
8
9
[root@uyhd000225 ms]# mount |column -s '@' -t
/dev/hda1 on / type ext3 (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/xvdb1 on /data type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@uyhd000225 ms]#

我以为他会输出以@为分隔符,但是没有安装我的期望输出

man column没有详细说明使用方法,info column也没有:

google发现他是输出分隔符,使用方法如下

1
2
3
4
5
6
7
8
[root@uyhd000225 testDir]# cat testcolumn
Jackie | 18 | male
Helen | 20 | female
Daniel Liu | 23 | male
[root@uyhd000225 testDir]# cat testcolumn | column -s '|' -t
Jackie        18    male
Helen         20    female
Daniel Liu    23    male
原文地址:https://www.cnblogs.com/liujiacai/p/9067318.html