Lum – Sort one column only, keeping remaining columns untouched

columnssorttext processing

How to (numerically) sort a specific column in a text file, without affecting other columns (irrespective of whether they are sorted or unsorted)? On other threads I found -s argument, but it does sort other columns.

Observation

$ cat tmp.txt
1 1
2 3
5 4
1 3

$ sort -s -n -k1,1 tmp.txt
1 1
1 3
2 3
5 4

Best Answer

As mentioned in the comments, you can't achieve what you want using sort alone.

You could cut the input file, feed relevant part to sort, and paste those.

$ paste -d' ' <(cut -d' ' -f1 input | sort -n) <(cut -d' ' -f2- input)
1 1
1 3
2 4
5 3