Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change how many spaces 'column -t' outputs between columns?

Tags:

sed

awk

column -t is amazing with one nit: How can I change how many spaces are output between columns? I want one. column -t gives two. For example,

echo -en '111 22 3\n4 555 66\n' | column -t

outputs

111  22   3
4    555  66

but I would like it to output the following:

111 22  3
4   555 66

I think I could run the output through sed regex to turn two spaces followed by a word boundary into a single space, but I'd like to avoid adding another tool to the mix unless its necessary.

Suggestions? Simple replacement commands that I could use instead of column -t which accomplish the same thing? Playing OFS games with awk doesn't seem like a drop-in replacement.

like image 427
Rhys Ulerich Avatar asked Dec 30 '25 09:12

Rhys Ulerich


1 Answers

You cannot change the builtin spacing of column. This leaves you with either switching to a different tool or post-processing. You can accomplish the ladder cheaply with sed to remove a single space before each number:

echo -en '111 22 3\n4 555 66\n' | column -t | sed 's/ \([0-9]\)/\1/g'

Output:

111 22  3
4   555 66
like image 148
mavam Avatar answered Jan 02 '26 01:01

mavam