util-linux / util-linux

http://en.wikipedia.org/wiki/Util-linux
GNU General Public License v2.0
2.63k stars 1.19k forks source link

column sometimes aligns last column incorrectly in non interactive shell mode #1618

Open aquilax opened 2 years ago

aquilax commented 2 years ago

The following example:

$ cat test.txt 
Date,2021-11-01,2021-12-01,2022-01-01,2022-02-01,2022-03-01
Row1,0,0,0,0,0
VeryLongDescriptionRow2,0,6000,6000,6000,0

In interactive shell produces correctly aligned table:

$ cat test.txt | column -t -s, -R 2,3,4,5,6,7 
Date                     2021-11-01  2021-12-01  2022-01-01  2022-02-01  2022-03-01
Row1                              0           0           0           0           0
VeryLongDescriptionRow2           0        6000        6000        6000           0

But when piped through less, the values in the last column after the first row are indented incorrectly

$ cat test.txt | column -t -s, -R 2,3,4,5,6,7 | less
Date                     2021-11-01  2021-12-01  2022-01-01  2022-02-01  2022-03-01
Row1                              0           0           0           0        0
VeryLongDescriptionRow2           0        6000        6000        6000        0

Tested with the the current master:

$ column -V
column from util-linux 2.38-rc2
$uname -a
Linux x280 5.13.0-30-generic #33-Ubuntu SMP Fri Feb 4 17:03:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
karelzak commented 2 years ago

You need to specify output width. For backward compatibility column(1) always calculates output according to terminal width or it defaults to 80 chars.

$ cat ~/test.txt |  ./column --output-width 120 -t -s, -R 2,3,4,5,6,7 > a; cat a;
Date                     2021-11-01  2021-12-01  2022-01-01  2022-02-01  2022-03-01
Row1                              0           0           0           0           0
VeryLongDescriptionRow2           0        6000        6000        6000           0

In the other tools, we have the default "as much as necessary" for the non-interative mode. It would be nice to have any special placeholder for this purpose in column(1), something like "--output-width unlimited". Let's add this to TODO.