Chinaunix

标题: sort [打印本页]

作者: yanjin415    时间: 2009-03-03 11:44
标题: sort
[root@localhost test]# sort -t: +1 video.txt
sort: open failed: +1: No such file or directory
我的系统是Fedora 10,是不是sort不再支持+n选项了?

备注sort的帮助:

[root@localhost test]# sort --help
Usage: sort [OPTION]... [FILE]...
Write sorted concatenation of all FILE(s) to standard output.

Mandatory arguments to long options are mandatory for short options too.
Ordering options:

-b, --ignore-leading-blanks ignore leading blanks
-d, --dictionary-order consider only blanks and alphanumeric characters
-f, --ignore-case fold lower case to upper case characters
-g, --general-numeric-sort compare according to general numerical value
-i, --ignore-nonprinting consider only printable characters
-M, --month-sort compare (unknown) < `JAN' < ... < `DEC'
-n, --numeric-sort compare according to string numerical value
-R, --random-sort sort by random hash of keys
--random-source=FILE get random bytes from FILE (default /dev/urandom)
--sort=WORD sort according to WORD:
general-numeric -g, month -M, numeric -n,
random -R
-r, --reverse reverse the result of comparisons

Other options:

-c, --check, --check=diagnose-first check for sorted input; do not sort
-C, --check=quiet, --check=silent like -c, but do not report first bad line
--compress-program=PROG compress temporaries with PROG;
decompress them with PROG -d
-k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1) -
when no POS2 specified, end of line is used
-m, --merge merge already sorted files; do not sort
-o, --output=FILE write result to FILE instead of standard output
-s, --stable stabilize sort by disabling last-resort comparison
-S, --buffer-size=SIZE use SIZE for main memory buffer
-t, --field-separator=SEP use SEP instead of non-blank to blank transition
-T, --temporary-directory=DIR use DIR for temporaries, not $TMPDIR or /tmp;
multiple options specify multiple directories
-u, --unique with -c, check for strict ordering;
without -c, output only the first of an equal run
-z, --zero-terminated end lines with 0 byte, not newline
--help display this help and exit
--version output version information and exit

POS is F[.C][OPTS], where F is the field number and C the character position
in the field; both are origin 1. If neither -t nor -b is in effect, characters
in a field are counted from the beginning of the preceding whitespace. OPTS is
one or more single-letter ordering options, which override global ordering
options for that key. If no key is given, use the entire line as the key.

SIZE may be followed by the following multiplicative suffixes:
% 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y.

With no FILE, or when FILE is -, read standard input.

*** WARNING ***
The locale specified by the environment affects sort order.
Set LC_ALL=C (by "export LC_LL=C") to get the traditional sort order that uses
native byte values.

Report bugs to <bug-coreutils@gnu.org>.
作者: 飞鸿无痕    时间: 2009-03-03 11:54
原帖由 yanjin415 于 2009-3-3 11:44 发表
[root@localhost test]# sort -t: +1 video.txt
sort: open failed: +1: No such file or directory
我的系统是Fedora 10,是不是sort不再支持+n选项了?

备注sort的帮助:

[root@localhost test]# sor ...


No such file or directory
应该是支持的吧,我的帮助信息里也没有哪个选项,但是支持!!!
另外不要犯低级的错误,是不是不存在那个文件???
作者: blackold    时间: 2009-03-03 11:59
标题: 回复 #1 yanjin415 的帖子
建议使用-k选项。
作者: yanjin415    时间: 2009-03-03 12:05
原帖由 blackold 于 2009-3-3 11:59 发表
建议使用-k选项。

请教,两个问题,
1.AS4上是支持+n选项的,附图

2.centos5.2,fedora10打了命令就是出错

用-k,是不是-k就是用来替换+n这个选项的?
作者: waker    时间: 2009-03-03 12:29
sort -k2
作者: chenwenming    时间: 2009-03-03 12:32
标题: 回复 #4 yanjin415 的帖子
对 用-k可以代替+n   
sort -t: -k2 video.txt
作者: merlin852    时间: 2009-03-03 12:35
info sort里会告诉你支不支持
作者: yanjin415    时间: 2009-03-03 13:00
原帖由 chenwenming 于 2009-3-3 12:32 发表
对 用-k可以代替+n   
sort -t: -k2 video.txt



超级晕
作者: 我是DBA    时间: 2009-03-03 13:02
标题: 回复 #8 yanjin415 的帖子
一般用-k比较好,通用
作者: blackold    时间: 2009-03-03 13:07
标题: 回复 #8 yanjin415 的帖子
+-n是较老系统上的选项,新系统建议使用期-k来代替。
作者: yanjin415    时间: 2009-03-03 16:56
原帖由 blackold 于 2009-3-3 13:07 发表
+-n是较老系统上的选项,新系统建议使用期-k来代替。



再请教一下,+-n是老系统上的,那为什么我的机器上这个可以运行
[root@localhost test]# sort -t: +0 -2 +3 video.txt

A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:532:4892
Boys in Company C:HK:192:2192
Star Wars:HK:301:4102
The Hill:HL:63:2972
Toy Story:HK:239:3972
还有,如果去掉+-n,那么这个又该怎么使用-k选项来替换,
[root@localhost test]# sort -t: +1.2 video.txt
sort: open failed: +1.2: No such file or directory
我的机器上运行这个出错,如上。


:(
作者: yanjin415    时间: 2009-03-03 21:39
up!!!!!
作者: chenwenming    时间: 2009-03-03 22:07
标题: 回复 #11 yanjin415 的帖子
[root@orzz root]# sort -t: +0 -2 +3   video.txt
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:532:4892
Boys in Company C:HK:192:2192
Star Wars:HK:301:4102
The Hill:HL:63:2972
Toy Story:HK:239:3972

跟下面是等价的

[root@orzz root]# sort -t: -k1,3 -k4 video.txt
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:532:4892
Boys in Company C:HK:192:2192
Star Wars:HK:301:4102
The Hill:HL:63:2972
Toy Story:HK:239:3972
================================
[root@orzz root]# sort -t: +1.2  video.txt      
Alien:HK:119:1982
Boys in Company C:HK:192:2192
Toy Story:HK:239:3972
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Aliens:HK:532:4892
The Hill:HL:63:2972

跟下面是等价的

[root@orzz root]# sort -t: -k2.3 video.txt
Alien:HK:119:1982
Boys in Company C:HK:192:2192
Toy Story:HK:239:3972
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Aliens:HK:532:4892
The Hill:HL:63:2972
作者: blackold    时间: 2009-03-03 22:41
标题: 回复 #11 yanjin415 的帖子
新系统也可以用+-n,只是不建议使用,以后可能删除。

具体参见手册。
作者: wtuter    时间: 2009-03-04 08:23
标题: 回复 #1 yanjin415 的帖子
你的文件有几列,+1是第二列排序的,你的应该支持的
作者: yanjin415    时间: 2009-03-04 09:38
原帖由 wtuter 于 2009-3-4 08:23 发表
你的文件有几列,+1是第二列排序的,你的应该支持的



+1的确是不支持的,你可以看我前面的抓图,
blackold 说的没错,感谢chenwenming的详细解说。呵呵,差不多弄明白了。
作者: 我是DBA    时间: 2009-03-04 09:54
标题: 回复 #13 chenwenming 的帖子
不错,学习了一把




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2