参考:Viewing Linux output in columns

功能

column命令把他的输入格式化多列显示。输入可以是文件,也可以是标准输入。

列优先,从左到右

显示的时候首先填满最左列,然后右列,顺序如下

1 4 7 10

2 5 8 11

3 6 9 12

测试文件

$ cat RR
I've been working on the railroad
All the live long day
I've been working on the railroad
Just to pass the time away Can't you hear the whistle blowing
Rise up so early in the morn
Can't you hear the whistle blowing
Dinah, blow your horn Dinah, won't you blow
Dinah, won't you blow
Dinah, won't you blow your horn
Dinah, won't you blow,
Dinah, won't you blow,
Dinah, won't you blow your horn

显示结果

$ column RR
I've been working on the railroad Dinah, blow your horn
All the live long day Dinah, won't you blow
I've been working on the railroad Dinah, won't you blow
Just to pass the time away Dinah, won't you blow your horn
Can't you hear the whistle blowing Dinah, won't you blow,
Rise up so early in the morn Dinah, won't you blow,
Can't you hear the whistle blowing Dinah, won't you blow your horn

行优先,从上到下

使用-x参数

$ cat RR
I've been working on the railroad
All the live long day
I've been working on the railroad
Just to pass the time away Can't you hear the whistle blowing
Rise up so early in the morn
Can't you hear the whistle blowing
Dinah, blow your horn Dinah, won't you blow
Dinah, won't you blow
Dinah, won't you blow your horn
Dinah, won't you blow,
Dinah, won't you blow,
Dinah, won't you blow your horn
$ column -x RR
I've been working on the railroad All the live long day
I've been working on the railroad Just to pass the time away
Can't you hear the whistle blowing Rise up so early in the morn
Can't you hear the whistle blowing Dinah, blow your horn
Dinah won't you blow Dinah won't you blow
Dinah, won't you blow your horn Dinah, won't you blow,
Dinah, won't you blow, Dinah, won't you blow your horn

保留空行

使用-e参数

$ cat RR
I've been working on the railroad
All the live long day
I've been working on the railroad
Just to pass the time away Can't you hear the whistle blowing
Rise up so early in the morn
Can't you hear the whistle blowing
Dinah, blow your horn Dinah, won't you blow
Dinah, won't you blow
Dinah, won't you blow your horn
Dinah, won't you blow,
Dinah, won't you blow,
Dinah, won't you blow your horn
$ column -e RR
I've been working on the railroad Dinah, blow your horn
All the live long day
I've been working on the railroad Dinah, won't you blow
Just to pass the time away Dinah, won't you blow
Dinah, won't you blow your horn
Can't you hear the whistle blowing Dinah, won't you blow,
Rise up so early in the morn Dinah, won't you blow,
Can't you hear the whistle blowing Dinah, won't you blow your horn

指定分隔符

默认的分隔符是空格,可以使用-s指定分隔符

$ cat abc
a:b:c:d:e
$ column -t -s: abc
a b c d e

把行创建出列表

上面指定分隔符的时候有个参数-t。-t用于根据-s指定的分隔符(默认为空格)将一行创建出几列。

这个参数经常用于查看mount输出。mount输出内容比较杂,每一行包含很多信息,信息之间以空格分隔

[root@localhost bin]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=2001952k,nr_inodes=,mode=)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=,mode=,ptmxmode=)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,net_prio,net_cls)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,devices)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuset)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,memory)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,perf_event)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,blkio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuacct,cpu)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,pids)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd- on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=,pgrp=,timeout=,minproto=,maxproto=,direct,pipe_ino=)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/ type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=402844k,mode=)
[root@localhost bin]# mount | column -t
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=2001952k,nr_inodes=,mode=)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=,mode=,ptmxmode=)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,net_prio,net_cls)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,devices)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuset)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,memory)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,perf_event)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,blkio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuacct,cpu)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,pids)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd- on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=,pgrp=,timeout=,minproto=,maxproto=,direct,pipe_ino=)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/ type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=402844k,mode=)

智障的设定

想想使用这个命令的场景,多数时候是因为输出结果一列显示太长了,多列显示能短一点。column虽然可以多列显示,但是你却不能控制他到底显示几列。这个设定相当智障。前面说到column显示规则,列优先,从左到右。他能显示的最大列数与你终端窗口允许显示最大列数有关,最左列显示不完才会再显示一列,以此类推。

pr解决了这个问题,参考:Linux命令——pr

不管你显示几列,每列宽度一样,如果某一行长度超过终端窗口宽度一半以上,那么你永远只能得到一列输出。更智障的设定

使用-c参数,你可以指定一列有多宽,不过貌似很少用得上。

最新文章

  1. Euler猜想
  2. wex5 实战 框架拓展之2 事件派发与data刷新
  3. matlab编译器和程序发布
  4. FusionCharts V3图表导出图片和PDF属性说明(转)
  5. 慕课网-安卓工程师初养成-1-3 使用记事本编写Java程序
  6. PL/SQL devloper 常用设置
  7. lintcode:哈希函数
  8. spring mvc 配置
  9. css动画结束后 js无法修改translated值 .
  10. RestTemplate 微信接口 text/plain HttpMessageConverter
  11. 代码生成器——实现生成pojo,sql,mapper接口
  12. js jquery select 操作 获取值,选中选项,增加,修改,删除
  13. Android Studio 签名 安全图片
  14. core_cm4_simd.h文件是干嘛的?
  15. XMind 入门教程
  16. ThreadException
  17. Mysql 表 创建 / 删除(基础3)
  18. CentOS 5.8下快速搭建FTP服务器
  19. Python Web学习笔记之多线程编程
  20. Django高级admin续

热门文章

  1. F5 BIG-IP – Useful SNMP oids to monitor
  2. VS2010配置OpenGL开发环境(转)
  3. web端自动化——selenium项目集成HTML测试报告
  4. linux 安装 rpm 的jdk
  5. art-template 弹出编辑
  6. [Visual Studio] - Unable to launch the IIS Express Web server 问题之解决
  7. idea使用maven+Tomcat
  8. 从零开始学Flask框架-002
  9. Git学习(一)——熟悉git操作流程
  10. AVR单片机教程——如何使用本教程