awk group by multiple columns and print max value with non-primary key

前端 未结 3 603
逝去的感伤
逝去的感伤 2021-01-21 10:29

i\'m new to this site and trying to learn awk. i\'m trying to find the maximum value of field3, grouping by field1 and print all the fields with maximum value. Field 2 contains

3条回答
  •  半阙折子戏
    2021-01-21 11:17

    With a little help of the sort command:

    sort -t, -k1,1 -k3,3nr file | awk -F, '!seen[$1]++'
    

提交回复
热议问题