Linux column command details

Function introduction:

Format output

How to use:

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.
option
Meaning
-c. number of characters Specify the column width to display
-s "separator“ When using the - t option, specify a separator (multiple separators allowed)
-t Determine the number of columns in the input row to create a table. The separator is the character specified in - s. If no separator is specified, the default is space
-x Change the order (left to right). The default order is (up → down)

Example

[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

Tags: Operation & Maintenance

Posted on Sat, 09 May 2020 07:45:20 -0700 by jmut