Lum – Create an ASCII art table from tabular data

columnscommand linecsvtext processing

Given perhaps comma- or tab-delimited input, I'd like to present a series of appropriately padded columns to stdout, so I can easily scan columnar information which would otherwise present rather messily.

I've tried troff-based solutions and while the simple demos have worked, feeding the command actual input has resulted in bizarre errors. I've currently resorted to using a sed-based method hack which is rather slow…

EDIT: column is quite a useful tool, however it'd be really awesome if I the columns had, say, a pipe character (|) between them so they do not appear to "float" in space and I can easily distinguish where each starts.

PS. This post's title used to read 'ASCII "table"', not 'ASCII-art table'. Edited to try and remove confusion.

Best Answer

Assuming a CSV file, you can use column(1) like so:

column -ts, your_file

This is included in the bsdmainutils package on my Debian distribution, so I'm not sure how portable it is.

Two more things to note:

  1. The above example is simplistic; explore the man page for more details on how to format your output.
  2. It does not fare well with quoted fields containing commas. I.e., it would consider a,b,"c,d" as four columns not three.
Related Question