I want to sort the line accorfing to the last number just before the space
. And this is a simplified example:
c3_abl_eerf_14 sasw
a.bla_haha_2 dnkww
s.hey_3 ddd
And this is the results I want:
a.bla_haha_2 dnkww
s.hey_3 ddd
c3_abl_eerf_14 sasw
I don't know how to do this, maybe by the command sort
? And, sometimes I used the sort
command, it may wrongly treat the 14 less than 2, I don't want this to happen.
this command chain works for your example:
sed -r 's/.*_([0-9]+) .*/\1 &/' file|sort -n|sed 's/[^ ]* //'
The idea is
sort by last number in the line, no matter where the number is:
awk -F'[^0-9]+' '{$0=(length($NF)?$NF:$(NF-1)) OFS $0}7' file|sort -n|sed 's/[^ ]* //'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With