2

I am trying to replicate the example of using teh GNU datamash utility to transpose a file. I get a different output though. Not sure what's happening.

Instructions: https://www.gnu.org/software/datamash/examples/#example_transpose

My output:

> ~/bin/Installed/datamash transpose < input.txt
Sample   Year   Count   id-123   2014   1002    id-99    2013    990    id-42    2014   2030    id-13    2014    599
>
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

2

I get the same output as you if I copy & paste input.txt from the example. If I replace multiple spaces with one tab it works as tab is the default separator.

$ datamash transpose < <(cat input.txt | tr -s ' ' '\t')
Sample  id-123  id-99   id-42   id-13
Year    2014    2013    2014    2014
Count   1002    990     2030    599

Or squeeze multiple spaces to one space and use option -t' ' as field separator:

$ datamash -t' ' transpose < <(cat input.txt | tr -s ' ')
Sample id-123 id-99 id-42 id-13
Year 2014 2013 2014 2014
Count 1002 990 2030 599

Or even better, use option -W or --whitespace as pointed out by steeldriver (thanks!):

$ datamash -W transpose < input.txt
Sample  id-123  id-99   id-42   id-13
Year    2014    2013    2014    2014
Count   1002    990     2030    599
Freddy
  • 25,565