ChinaUnix.net
相关文章推荐:

std sort 类名 参数

如题,在学习sort排序的时候,搜索了论坛的很多帖子。关于k参数,仍然没能理解。 这个例子是ywlscpl学长在一个帖子回复中举的。原帖我找不到了。 文本file如下 a1,9,2,21 a2,9,4,11 b1,8,7,15 b2,8,1,17 c1,7,6,24 c2,7,3,13 # sort -t, -k2 file c2,7,3,13 c1,7,6,24 b3,8,1,12 b2,8,1,17 b1,8,7,15 a1,9,2,21 a2,9,4,11 对于这个结果,我的理解是:如果k后面只有一个数字,表明每行从这个字段开始一直比较到该行最后一个字段...

by aijoex - Shell - 2009-07-09 18:50:43 阅读(4833) 回复(13)

相关讨论

$sort -t: +3 sort.txt sort: open failed: +3: No such file or directory 这个请指点

by drvial - Shell - 2009-04-23 18:03:05 阅读(1481) 回复(6)

$cat data OCT NOV DEC JUN JAN JUL MAY $sort -M data DEC JAN JUL JUN MAY NOV OCT 怎么不是想要的结果呢?

by sunbw001 - Shell - 2009-01-12 17:18:00 阅读(2646) 回复(18)

a.txt有如下内容 1 a b c e 1 a c b f 2 b c a g 5 e f a h 32 c d e h 1 a c b f 我希望第一列按照数字排序,并且去除完全相同的行,正确结果如下: 1 a b c e 1 a c b f 2 b c a g 5 e f a h 32 c d e h 命令1: sort -k 1 -n -u a.txt 结果: 1 a b c e 2 b c a g 5 e f a h 32 c d e h 命令2:sort -k 1 -u a.txt|sort -k 1 -n 结果正确! 还有其他办法吗?我觉得命令2的效率会变低的。

by Archie.Chen - Shell - 2006-07-14 11:52:44 阅读(6543) 回复(13)

[code]cat error.log |sort +2 -rn [/code] 查man. -r 是结果反转 -n 是把字符串作数字排序 但不知+2是做什么用,谢谢

by ccf - Shell - 2006-06-22 15:37:13 阅读(1026) 回复(2)

sort -m a.txt b.txt和sort a.txt b.txt的结果没有区别啊 还有-u参数的作用不明白,info里说是"output only the first of a sequence of lines that compare equal. " 是不是找出比较结果相同的所有行呢?如果有多个不同的行相等,是输出第一个还是所有都输出呢? 有文件a.txt,内容是 12:34:56 2:22:34 12:d:3 用sort -t : -k 1,1 -n -u c.txt 返回 2:22:34 12:34:56 意思是不是以numberic排序时,在12:34:56行的下一行找到一个第一...

by ailms - Shell - 2004-07-14 18:46:19 阅读(975) 回复(1)

在将普通的C字符串做为参数传递给一个函数。 void log(ostream o) { ofstream file ; file.open("/tmp/log.log", std::ios::app) ; file << o ; file.close() ; } 我直接这样调用log("hello world"),为什么会出现conversion from 'const char*' to non-scalar type 'std::ostream' requested的编译错误。 有谁知道怎么进行这种转换么??谢谢哦

by shiva - C/C++ - 2006-09-08 13:31:24 阅读(5271) 回复(12)

sort()函数我的理解,第三个参数好像是返回函数的指针 对于我自己定义的function object,带入总会报错,不知道原因,大家帮我看下 [code] sort(svec.begin(),svec.end(),str_cmp); //对sort的调用,对svec排序,sevc申明为vector svec bool str_cmp(string &str1,string &str2) //str_cmp的函数体,通过比较长度排序,后面true,false现在感觉是多余的 { return str1.length()

by perljoker - C/C++ - 2007-09-29 12:33:17 阅读(7567) 回复(12)

[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-...

by yanjin415 - Shell - 2009-03-04 09:54:41 阅读(3611) 回复(16)

我想把string中包含的特殊字符,如:,/去掉,怎么做? 即将内容是:1976/07/13的string改为19760713. 谢谢!

by zealotcat - C/C++ - 2003-07-24 10:04:41 阅读(843) 回复(3)

class config { public: config(const char *pName) { szConfigName = pName; } void init(); private: std::string szConfigName; } main() { config *pconfig = new config("test.config"); pconfig->init(); 问题出来init函数里,szConfigName没有值, 请问有什么好的办法,这个对象怎么没有保存起来呢? }

by nmzqzw - C/C++ - 2007-01-16 11:57:33 阅读(1156) 回复(7)