I have to sort the following list with a shell script and make the latest version appear on the bottom or top. How would I do that with shell tools only?release-5.0.0.rc1release-5.0.0.rc2release-5.0.0release-5.0.1release-5.0.10release-5.0.11release-5.0.13release-5.0.14release-5.0.15release-5.0.16release-5.0.17release-5.0.18release-5.0.19release-5.0.2release-5.0.20release-5.0.21release-5.0.22release-5.0.23release-5.0.24release-5.0.25release-5.0.26release-5.0.27release-5.0.28release-5.0.29release-5.0.3
How can I sort a list with major.minor.patch level and sometimes rc correctly?
shell script;awk;sed;python;sort
GNU sort has -V that can mostly deal with a list like that (details): -V, --version-sort        natural sort of (version) numbers within text$ cat versrelease-5.0.19release-5.0.19~pre1release-5.0.19-bigbugfixrelease-5.0.2release-5.0.20$ sort -V versrelease-5.0.2release-5.0.19~pre1release-5.0.19release-5.0.19-bigbugfixrelease-5.0.20However, those .rc* versions could be a bit of a problem, since they probably should be sorted before the corresponding non-rc version, if there happened to be both, that is. Some versioning systems (like Debian's), use suffixes starting with a tilde (~) to mark pre-releases, and they sort before the version without a suffix, which sorts before versions with other suffixes. Apparently this is supported by at least the sort on my system, as shown above (sort (GNU coreutils) 8.23). 