- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2011-03-15 11:33 编辑
我有6个文件:
1.unl
4301|280518.56|
4302|495374.42000000004|
4303|133506.70000000001|
4304|2370 ...
ztj111 发表于 2011-03-14 12:57 ![]()
试试Perl...
# cat combine_unl.pl- #!/usr/bin/env perl
- use strict;
- use warnings;
- my @gaData;
- my @gaItem;
- my %ghId;
- foreach my $sFn (1..6){
- my $sFile = "$sFn.unl";
- open(my $FHunl, "< $sFile") or die "can't open the $sFile\n";
- while(<$FHunl>){
- chomp;
- my ($sId, @aNum) = split(/\|/,$_);
- if($sId){
- $ghId{$sId} = 1;
- $gaData[$sFn]->{$sId} = \@aNum;
- $gaItem[$sFn] = scalar @aNum;
- }
- }
- close $FHunl;
- }
- foreach my $sId(sort{$a<=>$b} keys %ghId){
- print "$sId|";
- foreach my $sFn(1..6){
- if(exists $gaData[$sFn]->{$sId}){
- foreach(@{$gaData[$sFn]->{$sId}}){
- $_=sprintf("%.2f",$_) if(m/\.\d{3}/);
- s/\.00?$|0$//;
- print "$_|";
- }
- }
- else{
- print "0|" x $gaItem[$sFn];
- }
- }
- print "\n";
- }
复制代码 # perl combine_unl.pl
4301|280518.56|325050|116171|40645.56|150000|0|0|0|0|
4302|495374.42|249340|5990|478354.42|175000|0|0|0|0|
4303|133506.7|197819.17|19576|30045.1|0|0|0|0|0|
4304|237070.84|203240|310695|11669.7|0|0|0|0|299500|
4305|3096857|469172|70796|143136|0|0|2460205|155100|27600|
4306|2764.3|57344|2200|-8735.7|0|0|0|0|0|
4307|1040399.38|48000|31650|845500.18|28000|0|0|0|0|
4308|8803.32|106400|91518|6663.32|3000|0|0|0|0|
4309|39196.6|430800|26358|4366.6|0|0|0|0|0|
4310|1266023.69|2764000|380201|445132.69|2000000|0|0|721800|376701|
4311|566650.1|136460|81100|196969.1|3000|0|0|117900|62100|
4312|672057.74|603000|351562|88274.09|2000|0|458944|415000|324000|
4325|520|35060|18083|0|0|0|0|0|0|
4331|721229.4|473762|114400|-4640.6|0|0|624720|246900|109100|
4393|-3072.17|58800|16228|-9151.05|0|0|0|0|0| |
|