1

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
>
1

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
4
  • 1
    or you could simply add the -W (or --whitespace) option May 20 '19 at 17:01
  • Oh, didn't see that option. Very good point!
    – Freddy
    May 20 '19 at 17:02
  • Thank you folks! I am good now. May 20 '19 at 17:25
  • TBH I'm not sure if -W was always an option - or added recently May 20 '19 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.