1

I have a huge file with the structure similar to:

A B 1980
A C 1985
A B 1979
A D 1990
A C 1981

The task is to count frequencies of elements in the first two columns and also return the minimum number associated with each pair. To make more clear, the output should be:

A B 2 1979
A C 2 1981
A D 1 1990

My one-liner is (that behaves correctly on the toy data):

datamash -t' ' -s -g 1,2 count 1 min 3 < test.tsv

Question: I don't know exactly how count operation works in conjunction with the group by statement. If I understand the syntax correctly than the count 1 should count only elements in the first column. Could somebody please explain this?

2
  • 2
    I think it's counting the number of lines that match the --group key, regardless of the field number argument provided to the count operator.
    – JonDeg
    Jan 3 '20 at 10:17
  • 1
    Perhaps you want crosstab rather than groupby? ex. crosstab 2,1 (count is the default operation) and crosstab 2,1 min 3 - unfortunately I don't think it currently supports multiple operations so you'd need to do them separately Jan 3 '20 at 14:16

Your Answer

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

Browse other questions tagged or ask your own question.