[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-datamash] Output field separator switch?

From: Assaf Gordon
Subject: Re: [Bug-datamash] Output field separator switch?
Date: Wed, 30 Aug 2017 20:53:28 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1


On 30/08/17 06:06 PM, Dave Myron wrote:
> I'm late to the game discovering GNU datamash but it's fantastic! 

Thank you for your kind words.

> One thing I've found strange is that passing in the field separator also
> impacts the output. 
> For example, with a CSV file I, obviously, give -t, but that also causes
> datamash to print its output with a comma separator. This is surprising
> to me.

Indeed, this is the default behavior.
It is modeled after many other common unix utilities
which assume the input and output are of the same 'type'
(that is, CSV, tab-separated, white-space separated, etc.).

For example, if one does:

  $ cut -d: -f1,6 /etc/passwd

The "-d:" parameters sets both the input and output delimiters to ":".

However, I see GNU cut has an additional parameter "--output-delimiter",
exactly for cases like yours:

  $ cut -d: -f1,6 --output-delimiter=, /etc/passwd

I can add the same option to datamash, so it'll be:

   datamash -t, --output-delimiter="\t" [...]

But for an immediate solution, you can either use 'column' as you've
written (if you want white-space separated and aligned output),
or use 'sed' or 'tr' to replace all commas with a single tab:

   datamash -t, [....] | sed 's/,/\t/g'
   datamash -t, [....] | tr , '\t'

I'll reply to this thread when the new option is ready in datamash.

 - assaf

reply via email to

[Prev in Thread] Current Thread [Next in Thread]