How to sort and get last value?

hi,
would you guys help me ?
i have a file with some list, and i want to sort the list and get last value.
ex: cat testing.csv

$ cat testing.csv
a,1
a,2
a,3
d,5
b,3
c,3
c,4
etc

i want to get value like this :

a,3
b,3
c,4
d,5

if strings have only one digit and one letter

sort -rV file | rev | uniq -s2 | rev

--- Post updated at 04:56 ---

if strings have multiple numbers and letters

sort -rV file | sed -r 's/(.*),(.*)/\2 \1/' | uniq -f1 | sed -r 's/(.*) (.*)/\2,\1/'

--- Post updated at 05:01 ---

awk -F, '!t[$1]++' OFS="," <(sort -Vr file)

hi,

Thank you so much for your reply, I tried all command that you suggested, only this one is work:

sort -rV file | rev | uniq -s2 | rev

but still I get duplicate value,

ex: cat testing.csv
a,1
a,2
a,3
d,5
b,3
c,3
c,4
etc

i get like this:

a,2
a,3
b,3
c,4
d5

#a still have two value 2 and 3.

would you help me again?

--- Post updated at 06:24 AM ---

Hello,

Thank you so much for your reply, I tried all command that you suggest,
only this one is work:

sort -rV file | rev | uniq -s2 | rev

but still i get duplicate value,

ex: cat testing.csv
a,1
a,2
a,3
d,5
b,3
c,3
c,4
etc

i get like this:

a,2
a,3
b,3
c,4
d5

#a still have two value 2 and 3.

would you help me again?

Moderator comments were removed during original forum migration.
1 Like

:slight_smile:

sort -Vr testing.csv | sort -ut, -k1,1

I apologize, forgot to refresh the page, did not see the answer

1 Like

Thank you so much :slight_smile: