I can't make SORT with multiple columns work

sort -t ';' -k1,1 -k2,2 -k3,3 < unsorted

(only column-1 in file 'unsorted' is sorted correct)

11;13;08
12;23;24
14;16;15
17;09;04
2

1 Answer

Your expectations are wrong. sort does sort entire lines only. Thus, it will first look at the first column. If there are identical items, these will be sorted according to the second column.

To sort all these columns independently, you may need to first extract the different columns to separate text files, one per column, (awk can do that), then have these sorted (sort), then recombine these back into one file (paste, where the output can be formatted in columns with the column command).

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like