[clug] Sorting Version Numbers

jm jeffm at ghostgun.com
Mon Jan 8 23:12:37 UTC 2018


Say you have a set of version numbers of the for x.y.z-m.n.o where
x,y,x, m, n, and o are positive integers, eg 2.6.32-541.5.12. Is there a
one liner that can sort these? I've tried piping it into sort but that
only seems to work with the first number (eg sort -n -t\- -k2). I could
solve it with a scripting language but it's part of a one liner to
remove old kernels from the system.

Here's an example of real input the I'm trying to sort,

kernel-2.6.32-642.11.1.el7.x86_64
kernel-2.6.32-642.1.1.el7.x86_64
kernel-2.6.32-573.22.1.el7.x86_64
kernel-2.6.32-642.4.2.el7.x86_64
kernel-2.6.32-642.13.1.el7.x86_64

Anyone have any thoughts on this?


Jeff.






More information about the linux mailing list