I have a text file with entries representing build tags with version and build number in the same format as debian packages like this:
nimbox-apexer_1.0.0-12
nimbox-apexer_1.1.0-2
nimbox-apexer_1.1.0-1
nimbox-apexer_1.0.0-13
Using a shell script I need to sort the above list by 'version-build' and get the last line, which in the above example is nimbox-apexer_1.1.0-2
.
Get the latest build with:
Now, to catch it into a variable:
I haven't been able to find a simple way to do this. I've been looking at code to sort ip address, which is similar to my problem, and trying to change my situation to that one. This what I have come up with. Please tell me there is a simpler better way !!!
So starting with this data:
The first
sed
converts my problem into a sorting IPs problem keeping the original line to reverse the change at the end:The
sort
orders the line using the first four numbers which in my case represent mayor.minor.release.buildThe last
sed
eliminates the data used to sortFinally
tail
gets the last line which is the one I need.With GNU
sort
:GNU
tail
doesn't liketail -1
.The 2n,3n are the number of characters considered relevant in that field. Increase them if you use really big version numbers...