b***l 发帖数: 15 | 1 I want to sort a file by first field, and if first fields are the same, then
by second filed, and so on. how to do that using command "sort" or other
command?
"sort -k 1 file" will sort according to first field.
Thanks | p*****t 发帖数: 35 | 2 the behaviour you want is the default behaviour of sort
so just sort the file
jumpstart8# cat kk
1 2 3
1 3 3
1 4 3
1 2 4
jumpstart8# sort kk
1 2 3
1 2 4
1 3 3
1 4 3
see what I mean ?
【在 b***l 的大作中提到】 : I want to sort a file by first field, and if first fields are the same, then : by second filed, and so on. how to do that using command "sort" or other : command? : "sort -k 1 file" will sort according to first field. : Thanks
| b***l 发帖数: 15 | 3 But if I want to sort the followig first according column 1 and then column 3
and the column 2, how to do it? I want a general solution for any order of the
columns.
1 2 3
1 2 4
1 3 3
1 4 3
The expected result is:
1 2 3
1 3 3
1 4 3
1 2 4
then
【在 p*****t 的大作中提到】 : the behaviour you want is the default behaviour of sort : so just sort the file : jumpstart8# cat kk : 1 2 3 : 1 3 3 : 1 4 3 : 1 2 4 : jumpstart8# sort kk : 1 2 3 : 1 2 4
| f********h 发帖数: 149 | 4 sort -k1,1 -k3,3 -k2,2
info sort for more information
【在 b***l 的大作中提到】 : But if I want to sort the followig first according column 1 and then column 3 : and the column 2, how to do it? I want a general solution for any order of the : columns. : 1 2 3 : 1 2 4 : 1 3 3 : 1 4 3 : The expected result is: : 1 2 3 : 1 3 3
| b***l 发帖数: 15 | 5 Thx. That's the solution.
column 3
the
【在 f********h 的大作中提到】 : sort -k1,1 -k3,3 -k2,2 : info sort for more information
|
|