Linux命令——column
参考: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的更多相关文章
- Linux命令——pr
参考:Linux命令——column 前言 接触这个命令的初衷是我想把一个很长的单列输出设置成多列输出,奈何column的分列输出机制太智障,直到我发现了pr 参数 pr -# 输出指定的列数. -t ...
- 开发过程中常用的Linux命令
做Java开发好几年了,部署JavaWeb到服务器上,一般都选择Linux,Linux作为服务器真是不二之选,高性能,只要熟悉Linux,操作快捷,效率很高. 总结一下工作中常用的Linux命令备忘: ...
- Linux命令行技巧
Linux命令行技巧 命令 描述 • apropos whatis 显示和word相关的命令. 参见线程安全 • man -t man | ps2pdf - > man.pdf 生成一个PDF格 ...
- Linux 命令大全之Red Hat 7常用命令总结二
Linux 命令大全之RedHat7常用命令笔记... ----------------------------------------------------- 征服Linux从终端开始 ----- ...
- Linux 命令行
Linux 命令笔记 一.目录/文件 1.1 目录文件日常操作 . -> 当前目录 .. -> 上一级目录 .file/.dir -> 隐藏文件/文件夹 [ls] 查看指定目录文件 ...
- linux 命令中英文对照,收集
linux 命令中英文对照,收集 linux 命令英文全文 Is Linux CLI case-sensitive? The answer is, yes. If you try to run L ...
- (5)ps详解 (每周一个linux命令系列)
(5)ps详解 (每周一个linux命令系列) linux命令 ps详解 引言:今天的命令是用来看进程状态的ps命令 ps 我们先看man ps ps - report a snapshot of t ...
- (4)top详解 (每周一个linux命令系列)
(4)top详解 (每周一个linux命令系列) linux命令 top详解 引言:今天的命令是用来看cpu信息的top top 我们先看man top top - display Linux pro ...
- (3)lscpu详解 (每周一个linux命令系列)
(3)lscpu详解 (每周一个linux命令系列) linux命令 lscpu详解 引言:今天的命令是用来看cpu信息的lscpu lscpu 我们先看man lscpu display infor ...
随机推荐
- SignalR 传Model类型的参数
目录 集线器方法 js调用 集线器方法 集线器写了一个方法是这样的 public void test(string name, Customer customer) 第一个参数是string类型的,第 ...
- Cas(07)——建立使用Cas进行单点登录的应用
建立使用Cas进行单点登录的应用 目录 1.1加入cas-client-core-xxx.jar到classpath 1.2配置Filter 1.2.1AuthenticationFilter 1.2 ...
- C/C++文件操作经验总结
最近在做一个从groundtruth_rect.txt中读取按行存储的矩形元素(x, y, w, h),文本存储的格式如下: 310,102,39,50 308,100,39,50 306,99,39 ...
- idea查看接口及类的关系继承(UML)图
选中接口或类 显示结果: 如果需要添加其他的接口或类:点击右键 添加需要的接口或类: 显示结果:
- JavaFX窗体设置无边框
public void start(Stage stage) throws Exception { longStart(); Parent root = FXMLLoader.load(getClas ...
- pytorch1.0实现GAN
import torch import torch.nn as nn import numpy as np import matplotlib.pyplot as plt # 超参数设置 # Hype ...
- Tomcat中不能通过访问自己IP,但可以通过localhost/127.0.0.1访问
一.问题如下:局域网内,自己机器部署了一个tomcat应用,在本机上可以通过如下方式访问引用. http://localhost:8080/xxxx http://127.0.0.1:8080/xx ...
- Python入门学习——PyQt5程序基本结构
在学习python GUI部分时,一开始看书有点懵,看不懂框架,以下是个人学习所得(参考了别人的视频讲解),错误之处,望大家指教 #0.导入需要的包和模块from PyQt5.Qt import * ...
- WUSTOJ 1333: Sequential game(Java)
题目链接:1333: Sequential game Description Sequential detector is a very important device in Hardware ex ...
- 《MySQL数据库从入门到精通》 高级运维人才的必备书籍
众所周知,每年就业市场都会迎来千万量级的高校毕业生,然而企业招工难和毕业生就业难的矛盾却一直没有得到很好地解决.究其原因,主要矛盾还是在于传统的学历教育与企业实际需求相脱节.为了杜绝高校毕业生求职时常 ...