且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Unix bash:根据另一列的值选择一列中具有唯一值的行

更新时间:2021-11-10 21:43:12

使用 awk,您可以使用关联数组来管理此问题,该数组的键为第 1 列,值为第 2 列的最大值:

Using awk you can manage this using an associative array that has key as column-1 and value as maximum of column-2:

awk '$2 > a[$1]{a[$1] = $2} END{for (i in a) print i, a[i]}' file

1 4
2 3
3 3
4 4