columns are not properly aligned

Bug #1644703 reported by Rolf Leggewie
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
datamash (Ubuntu)
New
Undecided
Unassigned

Bug Description

Running datamash version 1.0.7-1 on Ubuntu trusty here. The output columns are not properly aligned (using "datamash -g 2 min 3 max 3 < /usr/share/doc/datamash/examples/scores.txt" for testing purposes). Please see attached screenshot.

Revision history for this message
Rolf Leggewie (r0lf) wrote :
Revision history for this message
Assaf Gordon (agn1) wrote :

Hello,

(I'm datamash's developer).

This is not a bug but intended operation: the 'scores.txt' is a tab-separated file.
datamash maintains the tabs as in the input - this is how it should be.

The output is not aligned on the terminal because some lines contain long text (longer than 8 characters) which then push the tab output to the next 'column'.

It is equivalent to the following situation:

  $ printf "a\t1\nvery-long-text\t2\n"
  a 1
  very-long-text 2

You can observe this with 'cat -A' (which displays tabs as '^I'):

  $ datamash -g 2 min 3 max 3 < scores.txt | cat -A
  Arts^I46^I88$
  Business^I79^I94$
  Health-Medicine^I72^I100$
  Social-Sciences^I27^I90$
  Life-Sciences^I14^I91$
  Engineering^I39^I99$

If you want to align tab-separated values properly on the screen, use 'expand':

  $ datamash -g 2 min 3 max 3 < scores.txt | expand -t20,30
  Arts 46 88
  Business 79 94
  Health-Medicine 72 100
  Social-Sciences 27 90
  Life-Sciences 14 91
  Engineering 39 99

regards,
 - assaf

Revision history for this message
Erik Auerswald (auerswal) wrote :

The 'column' utility from package 'bsdmainutils' can be used to properly align the columns:

[The web interface might "improve" the output by turning any run of space characters into a single space, removing the intended illustrative effect, as can be seen in the comment above]

    $ datamash -g 2 min 3 max 3 < /usr/share/doc/datamash/examples/scores.txt | column -s$'\t' -t
    Arts 46 88
    Business 79 94
    Health-Medicine 72 100
    Social-Sciences 27 90
    Life-Sciences 14 91
    Engineering 39 99

[With this specific input, one need not specify the separator, because no column comprises "blank" characters, i.e., the "-s" option can be omitted here, but not in general for the so called "TSV" format.]

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.