- 论坛徽章:
- 0
|
本帖最后由 zzy7186 于 2011-06-13 12:56 编辑
源文件:
- A 001 10
- A 002 20
- A 003 30
- B 004 40
- B 005 50
- C 006 60
- C 007 70
- D 008 80
- E 009 90
- E 010 100
复制代码 awk.file
- #!/bin/gawk -f
- {
- c[$1]++;
- a[$1,c[$1]]=$2;
- b[$1,$1,c[$1]]=$3;
- ml=ml>c[$1]?ml:c[$1];
- }
- END{
- n=asorti(c);
- for(i=1;i<=n;i++)
- {
- printf "%s\t",c[i];
- printf "%s%s\t",c[i],c[i];
- }
- printf "\n";
- for(j=1;j<=ml;j++)
- {
- for(i=1;i<=n;i++)
- {
- if(a[c[i],j]){
- printf "%s\t",a[c[i],j];
- }else{
- printf "\t";
- }
- if(b[c[i],c[i],j]){
- printf "%s\t",b[c[i],c[i],j];
- }else{
- printf "\t";
- }
- }
- printf "\n";
- }
- }
复制代码
- ./awk.file urlfile
- A AA B BB C CC D DD E EE
- 001 10 004 40 006 60 008 80 009 90
- 002 20 005 50 007 70 010 100
- 003 30
复制代码 |
|