- 论坛徽章:
- 32
|
稍微长了一些~- awk '{a[$1,$2]=a[$1,$2]?a[$1,$2]"\t"$3:$0;if(++b[$1]>m)m=b[$1]}END{for(i=1;i<=asort(a,c);i++){split(c[i],d,"\t");for(j=1;j<=m+2;j++)e[i]=e[i]?d[j]?e[i]"\t"d[j]:e[i]"\t0":d[j];print e[i]}}'
复制代码- [root@localhost test]# ls
- 1 2 3 4 5
- [root@localhost test]# awk '{a[$1,$2]=a[$1,$2]?a[$1,$2]"\t"$3:$0;if(++b[$1]>m)m=b[$1]}END{for(i=1;i<=asort(a,c);i++){split(c[i],d,"\t");for(j=1;j<=m+2;j++)e[i]=e[i]?d[j]?e[i]"\t"d[j]:e[i]"\t0":d[j];print e[i]}}' *
- A a 11 7 4 2 1
- B a 16 0 0 0 0
- B b 12 8 5 3 0
- C c 13 9 6 0 0
- D d 14 10 0 0 0
- E e 15 0 0 0 0
- [root@localhost test]#
复制代码 |
|