如题,在学习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)
$cat data OCT NOV DEC JUN JAN JUL MAY $sort -M data DEC JAN JUL JUN MAY NOV OCT 怎么不是想要的结果呢?
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的效率会变低的。
[code]cat error.log |sort +2 -rn [/code] 查man. -r 是结果反转 -n 是把字符串作数字排序 但不知+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行的下一行找到一个第一...
在将普通的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的编译错误。 有谁知道怎么进行这种转换么??谢谢哦
sort()函数我的理解,第三个参数好像是返回函数的指针
对于我自己定义的function object,带入总会报错,不知道原因,大家帮我看下
[code] sort(svec.begin(),svec.end(),str_cmp); //对sort的调用,对svec排序,sevc申明为vector
[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-...
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没有值, 请问有什么好的办法,这个对象怎么没有保存起来呢? }