I have a file that looks like this:
foo03a
foo02b
quux01a
foo01a
foo02a
foo01b
foo03b
quux01b
I'd like it ordered by the last character (so a and b appear together) and then by the preceding number, and then by the prefix (though this is not essential). So that it results in:
foo01a
quux01a
foo02a
foo03a
foo01b
quux01b
foo02b
foo03b
It actually doesn't particularly matter where quux01a and quux01b appear, as long as they're in the relevant group -- they can appear as shown, before foo01b, or after foo03b.
Why? These are server names used in a blue/green deployment, so I want the 'A' servers together, then the 'B' servers.
I found the -k switch to GNU sort, but I don't understand how to use it to specify a particular character, counting from the end of the string.
I tried cat foos | rev | sort | rev, but that sorts foo10a and foo10b (when we count up that far) into the wrong place.
sort -k1.6 -k1.4,1.5n -k1.1,1.3 file