免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 Shell sort
12下一页
最近访问板块 发新帖
查看: 4607 | 回复: 16
打印 上一主题 下一主题

sort [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-03 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]# 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>.

论坛徽章:
0
2 [报告]
发表于 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
应该是支持的吧,我的帮助信息里也没有哪个选项,但是支持!!!
另外不要犯低级的错误,是不是不存在那个文件???

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
3 [报告]
发表于 2009-03-03 11:59 |只看该作者

回复 #1 yanjin415 的帖子

建议使用-k选项。

论坛徽章:
0
4 [报告]
发表于 2009-03-03 12:05 |只看该作者
原帖由 blackold 于 2009-3-3 11:59 发表
建议使用-k选项。

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

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

用-k,是不是-k就是用来替换+n这个选项的?

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
5 [报告]
发表于 2009-03-03 12:29 |只看该作者
sort -k2

论坛徽章:
0
6 [报告]
发表于 2009-03-03 12:32 |只看该作者

回复 #4 yanjin415 的帖子

对 用-k可以代替+n   
sort -t: -k2 video.txt

论坛徽章:
0
7 [报告]
发表于 2009-03-03 12:35 |只看该作者
info sort里会告诉你支不支持

论坛徽章:
0
8 [报告]
发表于 2009-03-03 13:00 |只看该作者
原帖由 chenwenming 于 2009-3-3 12:32 发表
对 用-k可以代替+n   
sort -t: -k2 video.txt



超级晕

论坛徽章:
0
9 [报告]
发表于 2009-03-03 13:02 |只看该作者

回复 #8 yanjin415 的帖子

一般用-k比较好,通用

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
10 [报告]
发表于 2009-03-03 13:07 |只看该作者

回复 #8 yanjin415 的帖子

+-n是较老系统上的选项,新系统建议使用期-k来代替。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP