Linux column命令格式化显示

发布于 分类 Linux

更新于 2016-07-18

最近在使用AWK分析所有IP每天的访问数时,默认显示结果只是一个空格隔开,因为不是格式化输出不便于更直观的浏览,最开始尝试用printf感觉很繁琐,而且数据宽度不好预判,后来发现column命令可以比较轻松解决我的问题。

帮助文档 #man column

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.

下面是一个demo:

[root@localhost ~]# echo '格式化前' && mount && echo '格式化后' && mount |column -t 

-- The End --

本文标题: Linux column命令格式化显示

本文地址: https://seonoco.com/blog/linux-column-command-format-display

本页面显示内容已针对移动端进行优化,点击查看完整版本