Redian新闻
>
How to do that using "sort" command?
avatar
How to do that using "sort" command?# Unix - 噫吁兮,危乎高哉
b*l
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
avatar
p*t
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

avatar
b*l
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

avatar
f*h
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

avatar
b*l
5
Thx. That's the solution.

column 3
the

【在 f********h 的大作中提到】
: sort -k1,1 -k3,3 -k2,2
: info sort for more information

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。