参考: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参数,你可以指定一列有多宽,不过貌似很少用得上。

Linux命令——column的更多相关文章

  1. Linux命令——pr

    参考:Linux命令——column 前言 接触这个命令的初衷是我想把一个很长的单列输出设置成多列输出,奈何column的分列输出机制太智障,直到我发现了pr 参数 pr -# 输出指定的列数. -t ...

  2. 开发过程中常用的Linux命令

    做Java开发好几年了,部署JavaWeb到服务器上,一般都选择Linux,Linux作为服务器真是不二之选,高性能,只要熟悉Linux,操作快捷,效率很高. 总结一下工作中常用的Linux命令备忘: ...

  3. Linux命令行技巧

    Linux命令行技巧 命令 描述 • apropos whatis 显示和word相关的命令. 参见线程安全 • man -t man | ps2pdf - > man.pdf 生成一个PDF格 ...

  4. Linux 命令大全之Red Hat 7常用命令总结二

    Linux 命令大全之RedHat7常用命令笔记... ----------------------------------------------------- 征服Linux从终端开始 ----- ...

  5. Linux 命令行

    Linux 命令笔记 一.目录/文件 1.1 目录文件日常操作 . -> 当前目录 .. -> 上一级目录 .file/.dir -> 隐藏文件/文件夹 [ls] 查看指定目录文件 ...

  6. linux 命令中英文对照,收集

    linux 命令中英文对照,收集   linux 命令英文全文 Is Linux CLI case-sensitive? The answer is, yes. If you try to run L ...

  7. (5)ps详解 (每周一个linux命令系列)

    (5)ps详解 (每周一个linux命令系列) linux命令 ps详解 引言:今天的命令是用来看进程状态的ps命令 ps 我们先看man ps ps - report a snapshot of t ...

  8. (4)top详解 (每周一个linux命令系列)

    (4)top详解 (每周一个linux命令系列) linux命令 top详解 引言:今天的命令是用来看cpu信息的top top 我们先看man top top - display Linux pro ...

  9. (3)lscpu详解 (每周一个linux命令系列)

    (3)lscpu详解 (每周一个linux命令系列) linux命令 lscpu详解 引言:今天的命令是用来看cpu信息的lscpu lscpu 我们先看man lscpu display infor ...

随机推荐

  1. jenkins编译时文件存放的位置

    1.首先随便打包编译一下 2.查看编译执行的目录 [root@bogon ~]# ls /root/.jenkins/workspace/pipline-test/ CHANGE_LOGS.html ...

  2. robot:List变量的使用注意点

    创建list类型变量,两种方式,建议使用Create List关键字 使用该列表变量时需要变为${}方式,切记切记!

  3. mycat搭建环境

    macos完全卸载mysql: https://blog.csdn.net/u012721519/article/details/55002626 踩过的坑: mycat1.6不支持单库分表; 最少要 ...

  4. C++ 理解函数对象与lambda表达式

    参考<21天学通C++>第21与第22章节,对函数对象进行介绍,同时通过lambda表达式这一匿名函数对象的简洁方式加深对函数对象的理解.本篇博文的主要内容是: (1) 函数对象的概念: ...

  5. 通过noVNC和websockify连接到QEMU/KVM 转

    开源项目 QEMU.KVM.libvirt 实现了创建虚拟机,启动虚拟机,监控虚拟机.我们解决了从无到有的问题,这时就该考虑从有到优了.尽管我们能使用 SSH 的方式来登录使用虚拟机,但这种方式从感觉 ...

  6. Mowing the Lawn【线性dp + 单调队列优化】

    题目链接:https://ac.nowcoder.com/acm/contest/2652/G 题目大意:与上一篇博客 烽火传递 差不多. 1.一共n头羊,若超过m头连续的羊在一起,就会集体罢工,每头 ...

  7. 小程序里实现 watch 和 computed

    小程序里的自定义组件里是有数据监听器的,可以监听对应数据的变化来执行callBack,但是页面Page里没有对应的api就显的很生硬,比如某个数据变了(如切换城市)需要重新刷页面,如果不做监听,每次都 ...

  8. NMF包的安装

    win10 操作系统,R3.4版本 NMF包的下载 source("https://bioconductor.org/biocLite.R") biocLite("Bio ...

  9. Word 下划线无法对齐?用表格替代下划线(论文封面必备)

    1. 前言 在使用Word排版制作合同或者论文封面时,我们可能会使用一些下划线,但是,你在下划线上输入内容后,发现下划线会随着内容而增长,根本无法与上下的下划线对齐.有什么好办法可以解决这一问题呢?其 ...

  10. python爬取盘搜的有效链接

    因为盘搜搜索出来的链接有很多已经失效了,影响找数据的效率,因此想到了用爬虫来过滤出有效的链接,顺便练练手~ 这是本次爬取的目标网址http://www.pansou.com,首先先搜索个python, ...