0

I have a file of software versions of the form a.b.c where a, b, and c are integers. For example

2.10.1
1.10.3
10.4.9
1.9.10 
1.2.30

I have tried:

sort -k 1n -k1,3 -t $'.' versions

And this works but only on the first column. How do I specify sub-sorting on column 2 and 3?

1 Answer 1

2

This sorts your mentioned version numbers right. The separator is set to ., the comparison is numerically by -n and the order is first from column 1 to 1-k 1,1, second from column 2 to 2 -k 2,2 and third from column 3 to 3 -k 3,3.

$ echo '2.10.1
1.10.3
10.4.9
1.9.10
1.2.30' | sort -t '.' -n -k 1,1 -k 2,2 -k 3,3

1.2.30
1.9.10
1.10.3
2.10.1
10.4.9
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, thanks, I had come up with some unwieldy cmd line perl. Nice and clean Matthias, cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.