- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2010-12-17 12:30 编辑
我也在这地方犯难呢.... 现在想cat 出一个全部的$1的列表 然后把f1 f2 f3 f3 f5 f6补零 再awk到一 ...
bjsfeng 发表于 2010-12-17 11:19 ![]()
嗯要一天.....
試試這個吧
file: item_combine.pl
- use strict;
- my @aItem=(["item"]);
- my $sCnt=0;
- my $sMax_item=0;
- sub get_data{
- my ($sFile, $sCnt) = @_;
- open(FHin, "<" , $sFile) or die "can't open $sFile\n";
- while(<FHin>){
- my($sItem, $sNum, $sX) = split;
- if($sX){
- print "got some error: $_";
- }
- $aItem[$sItem]->[$sCnt] = $sNum;
- $sMax_item = $sItem if($sItem > $sMax_item);
- }
- close FHin;
- }
- foreach(@ARGV){
- $sCnt++;
- $aItem[0]->[$sCnt] = $_;
- get_data($_,$sCnt);
- }
- printf("%4s ", $aItem[0]->[0]);
- printf("%10s ",$_) foreach(@{$aItem[0]}[1..$sCnt]);
- print "\n";
- foreach my $sItem (1 .. $sMax_item){
- printf("%-4d ",$sItem);
- foreach (1 .. $sCnt){
- printf("%10d ", $aItem[$sItem]->[$_]);
- }
- print "\n"
- }
复制代码 perl item_combine.pl a.txt b.txt c.txt
item a.txt b.txt c.txt
1 11456798 211233 311343
2 12456764 0 321343
3 13489743 231324 331324
4 0 241234 0
5 15136633 0 0
(注:内容有改过) |
|