Sort by second column in numerical and first order alphabetically

I have 2 columns, I want to sort them using bash.

I used the command:

sort -k2 -n c 9 c 11 c 11 sh 11 c 13 c 15 txt 47 txt 94 txt 345 txt 628 sh 3673 

This is the result, but I need them to be sorted as follows:

 c 9 c 11 c 11 c 13 c 15 sh 11 sh 3673 txt 47 txt 94 txt 345 txt 628 

Any ideas?

+5
source share
1 answer

First sort by column 1, then by 2:

 sort -k1,1 -k2,2n file.txt 
+9
source

Source: https://habr.com/ru/post/1245910/


All Articles