更新时间: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