Keep the last uniq record only

Hi folks,

Below is the content of a file 'tmp.dat', and I want to keep the uniq record (key by first column). However, the uniq record should be the last record.

302293022|2|744124889|744124889
302293022|3|744124889|744124889
302293022|4|744124889|744124889
302293022|5|744124889|744124889
302293022|6|744124889|744124889
302293022|7|744124889|744124889
302293022|8|744124889|744124889
302293022|9|744124889|744124889
302293022|10|744124889|744124889
302293022|11|744124889|744124889

Output:

302293022|11|744124889|744124889

Any ideas... I was playing around with the 'sort' and 'uniq' commands but could not get very far.

Thanks,
CB

Hi
Not sure, i understood you correctly. If it is always the last record, why not 'tail -1'.

Guru.

If the last record that you wanted to keep always has the highest value in column 2, then:

sort -t\| -k1,1 -k2,2rn tmp.dat |sort -t\| -mu -k1,1
awk -F \| '{if ($2>a[$1]) {a[$1]=$2;b[$1]=$0}} END {for (i in a) print b}' tmp.dat

Hi.

From some notes I made for a uniq-like section of code I wrote long ago, discussing whether, in a sequence of same items (in a specific field), the first or last occurrence is kept and printed:

cheers, drl