Unix sort of version numbers

The -V option is the nicest, but I wanted to stay away from installing new/other software since my sort didn’t have that option.

This is the command that worked for me in the end:

sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n test.txt

From comments:

  • To reverse the order: sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr
  • To skip the v prefix: sort -t. -k 1.2,1n -k 2,2n -k 3,3n -k 4,4n

Leave a Comment