- 论坛徽章:
- 18
|
本帖最后由 bikkuri 于 2014-02-17 15:51 编辑
把第二条命令中END后面输出部分循环里的i<length(b)改成i<NR以后可以输出,但是输出内容没有排序,和原文件一样,也就是说排序函数没有起作用。
同时在END后面print length(b)发现length(b)的值其实是0.- root@box:~/test# awk '{a[$4$3NR]=$0;b[i++]=$4$3NR}END{print length(a),a,length(b),b;quicksort(b,0,length(b)-1);for(i=0;i<NR;i++){print a[b[i]]}}function quicksort(b,p,r,q){if(p<r){q=partition(b,p,r);quicksort(b,p,q-1);quicksort(b,q+1,r)}}function partition(b,p,r,x,m,j,t){x=b[r];m=p;for(j=p;j<r;j++){if(b[j]<x){t=b[m];b[m]=b[j];b[j]=t;m++}}t=b[r];b[r]=b[m];b[m]=t;return m}' test.txt
- 0 0
- 2014-02-06 13:45:11 root hp7 modified GSGN.db 92
- 2014-02-06 13:45:10 john hp7 modified SGSN.d 63
- 2014-02-06 13:50:11 root hp8 modified MME.db 66
- 2014-02-06 13:45:11 jane hp6 modified HSS.db 92
- 2014-02-06 13:45:10 sam hp7 modified SGSN.db 63
- 2014-02-06 13:50:11 root hp8 modified PCRF.db 66
- root@box:~/test#
复制代码 |
|