由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - How to do that using "sort" command?
相关主题
how to print the last 2 columns of a text file?再次急问: *.tgz 文件怎么解?
sort problem双面打印
shell programming problemshelp on job control commands
A question about show diff on vimquestion about temperay file in sort command
A display question for VIMwait on line: simple question
shell script for column operationHow to use the command history in SUN?
how to insert a column for all slected rows in emacs (转载)how to run background process after logout
Re: how to write a recursive fcn using ksh to find all the occurancesHow to sort email address?
相关话题的讨论汇总
话题: sort话题: command话题: column话题: do话题: using
进入Unix版参与讨论
1 (共1页)
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

1 (共1页)
进入Unix版参与讨论
相关主题
How to sort email address?A display question for VIM
Re: 怎么在UNIX下面放CD?shell script for column operation
what's the use of "ta"how to insert a column for all slected rows in emacs (转载)
have u use ";" in pine?Re: how to write a recursive fcn using ksh to find all the occurances
how to print the last 2 columns of a text file?再次急问: *.tgz 文件怎么解?
sort problem双面打印
shell programming problemshelp on job control commands
A question about show diff on vimquestion about temperay file in sort command
相关话题的讨论汇总
话题: sort话题: command话题: column话题: do话题: using