Linux column命令详解

2020/05/09 15:48
阅读数 733
AI总结

功能介绍:

格式化输出

使用放法:

NAME
     column - columnate lists
SYNOPSIS
     column [-tx] [-c columns] [-s sep] [file ...]
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.
     The options are as follows:
     -c      Output is formatted for a display columns wide.
     -s      Specify a set of characters to be used to delimit columns for the -t option.
     -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.
     -x      Fill columns before filling rows.
     Column exits 0 on success, >0 if an error occurred.
选项
含义
-c 字符数 指定显示的列宽
-s“ 分隔符 “ 使用-t选项时,指定分隔符(允许指定多个分隔符)
-t 判断输入行的列数来创建一个表。分隔符是使用在-s中指定的字符。如果没有指定分隔符,默认是空格
-x 更改排列顺序(左→右)。默认的顺序为(上→下)

实例

[root@gz4 ~]# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  eth0: 552252052 5390427    0    0    0     0          0         0 658218877 5458776    0    0    0     0       0          0
    lo:  399056    8144    0    0    0     0          0         0   399056    8144    0    0    0     0       0          0
[root@gz4 ~]# cat /proc/net/dev|column -t
Inter-|  Receive    |        Transmit
face     |bytes     packets  errs      drop  fifo  frame  compressed  multicast|bytes  packets    errs     drop  fifo  colls  carrier  compressed
eth0:    552254150  5390452  0         0     0     0      0           0                658222004  5458797  0     0     0      0        0           0
lo:      399056     8144     0         0     0     0      0           0                399056     8144     0     0     0      0        0           0

[root@gz4 ~]# cat 1.txt 
Jackie | 18 | male 
Helen | 20 | female 
Daniel Liu | 23 | male
[root@gz4 ~]# cat 1.txt |column  -s '|' -t
Jackie        18    male 
Helen         20    female 
Daniel Liu    23    male

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
AI总结
返回顶部
顶部