i have a list of resolutions (mobile devices, monitors etc...) and i want to sort them by resolution using bash/vim
i have (not ordered):
1024 x 480
96 x 120
1024 x 600
100 x 120
800 x 1280
64 x 98
640 x 320
64 x 128
640 x 960
800 x 480
80 x 120
then when i do:
cat file | sort -u
i get:
100 x 120
1024 x 480
1024 x 600
640 x 320
640 x 960
64 x 128
64 x 98
800 x 1280
800 x 480
80 x 120
96 x 120
why it not sorted like this and how can i do it?
64 x 98
64 x 128
80 x 120
96 x 120
100 x 120
640 x 320
640 x 960
800 x 1280
800 x 480
1024 x 480
1024 x 600
you can use
sort -n -k1 -k3 file
This does the sort based on the numeric prefix so you'd get the list sorted by the first number
this produces
64 x 98
64 x 128
80 x 120
96 x 120
100 x 120
640 x 320
640 x 960
800 x 480
800 x 1280
1024 x 480
1024 x 600
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