- 论坛徽章:
- 2
|
回复 yinyuemi
4301|0|0|0|0|0|0|0|0|0|
4302|0|0|0|0|0|0|0|0|0|
4303|0|0|0|0|0|0|0|0|0|
...
ztj111 发表于 2011-03-16 12:52 ![]()
我的可以,- awk '{sub(".unl","",FILENAME);print FILENAME"|"$0|"sort -t \"|\" -k2n -k1"}' [1-6].unl |awk -F'|' '{for(i=3;i<NF;i++) {x=sprintf("%0.2f",$i);a[$2"|"$1]=(length(a[$2"|"$1])==0)?"|"x:a[$2"|"$1]"|"x}}{p=($2!=v)?++p:p;b[p]=$2;v=$2}END{for(i=1;i<=p;i++){printf b[i];for(j=1;j<=6;j++){if(j==2 || j==6 ||j==4){printf a[b[i]"|"j]?a[b[i]"|"j]:"|0|0"} else {printf a[b[i]"|"j]?a[b[i]"|"j]:"|0"}}print"|"}}'
- 4301|280518.56|325050.00|116171.00|40645.56|150000.00|0.00|0|0|0|
- 4302|495374.42|249340.00|5990.00|478354.42|175000.00|0.00|0|0|0|
- 4303|133506.70|197819.17|19576.00|30045.10|0|0|0|0|0|
- 4304|237070.84|203240.00|310695.00|11669.70|0|0|0|0.00|299500.00|
- 4305|3096857.00|469172.00|70796.00|143136.00|0|0|2460205.00|155100.00|27600.00|
- 4306|2764.30|57344.00|2200.00|-8735.70|0|0|0|0|0|
- 4307|1040399.38|48000.00|31650.00|845500.18|28000.00|0.00|0|0|0|
- 4308|8803.32|106400.00|91518.00|6663.32|3000.00|0.00|0|0|0|
- 4309|39196.60|430800.00|26358.00|4366.60|0|0|0|0|0|
- 4310|1266023.69|2764000.00|380201.00|445132.69|2000000.00|0.00|0|721800.00|376701.00|
- 4311|566650.10|136460.00|81100.00|196969.10|3000.00|0.00|0|117900.00|62100.00|
- 4312|672057.74|603000.00|351562.00|88274.09|2000.00|0.00|458944.00|415000.00|324000.00|
- 4325|520.00|35060.00|18083.00|0|0|0|0|0|0|
- 4331|721229.40|473762.00|114400.00|-4640.60|0|0|624720.00|246900.00|109100.00|
- 4393|-3072.17|58800.00|16228.00|-9151.05|0|0|0|0|0|
复制代码 如果你文件名都是[0-9].unl,再试试:- awk '{print FILENAME+0"|"$0|"sort -t \"|\" -k2n -k1"}' [1-6].unl |awk -F'|' '{for(i=3;i<NF;i++) {x=sprintf("%0.2f",$i);a[$2"|"$1]=(length(a[$2"|"$1])==0)?"|"x:a[$2"|"$1]"|"x}}{p=($2!=v)?++p:p;b[p]=$2;v=$2}END{for(i=1;i<=p;i++){printf b[i];for(j=1;j<=6;j++){if(j==2 || j==6 ||j==4){printf a[b[i]"|"j]?a[b[i]"|"j]:"|0|0"} else {printf a[b[i]"|"j]?a[b[i]"|"j]:"|0"}}print"|"}}'
复制代码 |
|