I have thousands data like this:
abc_1
abc_2
abc_3
abc_4
def_1
def_2
def_3
ghi_1
ghi_2
I want to filter it to get only data with the highest number which is abc_4, def_3, ghi_2
.
How I can get it?
I have thousands data like this:
abc_1
abc_2
abc_3
abc_4
def_1
def_2
def_3
ghi_1
ghi_2
I want to filter it to get only data with the highest number which is abc_4, def_3, ghi_2
.
How I can get it?
Using awk, as implied by your tags:
If you have GNU awk > 4.0 you can do the sorting internally
Alternatively, if you have Miller you can do a groupwise max using the
stat1
verb:or with GNU datamash
or for your specific input, assuming that the prefix strings are fixed length, using standard utilities
sort
anduniq
: