- 求职 : 机器学习
- 论坛徽章:
- 79
|
本帖最后由 zsszss0000 于 2015-03-20 12:41 编辑
- awk '{a[$2]++;year=substr($1,1,4);b[$2,year]++;c[year]=1;}END{len=asorti(c,cc);printf "数字""\t""次数""\t";for(i=1;i<=len;i++)printf cc[i]"\t";printf"\n";for( ia in a){printf ia"\t"a[ia]"\t";for (ic in cc){if((ia,cc[ic]) in b){printf b[ia,cc[ic]]"\t"}else{printf"0\t"} }printf "\n"}}' file | sort -n
复制代码 不对这个错了,还得调试一下,下面这个试一试- awk '{a[$2]++;year=substr($1,1,4);b[$2,year]++;c[year]=1;}END{len=asorti(c,cc);printf "数字""\t""次数""\t";for(i=1;i<=len;i++)printf cc[i]"\t";printf"\n";for( ia in a){printf ia"\t"a[ia]"\t";for (ic=1;ic<=len;ic++){if((ia,cc[ic]) in b){printf b[ia,cc[ic]]"\t"}else{printf"0\t"} }printf "\n"}}' file | sort -n
复制代码- 数字 次数 2004 2005 2006 2011 2014 2015
- 0546 1 0 1 0 0 0 0
- 2810 1 0 1 0 0 0 0
- 2998 1 0 0 0 0 0 1
- 3251 4 0 0 0 2 1 1
- 3822 1 1 0 0 0 0 0
- 4209 1 0 0 1 0 0 0
- 4311 1 0 1 0 0 0 0
- 4350 1 0 1 0 0 0 0
- 5665 1 1 0 0 0 0 0
- 6747 1 0 1 0 0 0 0
- 7801 2 1 0 0 0 1 0
- 8027 2 1 1 0 0 0 0
- 8141 1 1 0 0 0 0 0
复制代码 回复 4# coldface
|
|