Command Line – Layout Tab Separated List Nicely

command linecsvtabulationtext processing

Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance

var1  var2  var3
var_with_long_name_which_ruins_alignment  var2 var3

Is there an easy way to render them aligned?

var1                                      var2  var3
var_with_long_name_which_ruins_alignment  var2  var3

Best Answer

So, the answer becomes:

column -t file_name

Note that this splits columns at any whitespace, not just tabs. If you want to split on tabs only, use:

column -t -s $'\t' -n file_name

The -s $'\t' sets the delimiter to tabs only and -n preserves empty columns (adjacent tabs).

P.S.: Just want to point out that the credit goes to Alex as well. The original hint was provided by him as a comment to the question, but was never posted as an answer.

Related Question