Linux:columnコマンドでデリミタを指定して表形式で出力する方法

スポンサーリンク

columnコマンドでデリミタを指定して表形式で出力する方法

columnコマンドでデリミタを指定して表形式で出力するには-sオプションを指定します。

-tオプションは表形式で出力するオプションです。

 

オプションの説明

 -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.

 

-sオプションを指定した場合

$ cat test.txt
a,b,c
100,2,3
4,500,6
$ cat test.txt | column -t -s ,
a    b    c
100  2    3
4    500  6

 

-sオプションを指定しない場合(デフォルトはホワイトスペース区切り)

$ cat test.txt
a,b,c
100,2,3
4,500,6
$ cat test.txt | column -t
a,b,c
100,2,3
4,500,6

$ cat test2.txt
a b c
100 2 3
4 500 6
$ cat test2.txt | column -t
a    b    c
100  2    3
4    500  6