且构网

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

重击:查找一列中的重复项,根据另一列的比较删除行

更新时间:2022-11-14 13:14:40

sort -rk2 file | awk '!seen[$1]++'

按日期排序文件(第二列),然后删除重复项。这样,您可以在第一列中保留最新的唯一性。

Sort the file by date (the second column) and then remove the duplicates. This way you keep the most recent uniques per first column.

或者使用一个awk脚本

Or with one awk script

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