The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 11-17-2008
summer_cherry summer_cherry is online now Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
hi below perl may help you a little

usage: perl a.pl NUM FILE1 FILE2 [here NUM indicate how many lines will be header]
Code:
a:
*****
line 1
line 2
1 2 3 4 5
Code:
b:
*****
line 3
line 4
9 8 7 6 5
output:
Code:
*****
line 1
line 2
line 3
line 4
10 10 10 10 10
Code:
$header=shift;
undef $/;
my(@head,@body,@foot);
while($file=shift){
	open FH,"<$file" or die "Can not open file $_";
	my $str=<FH>;
	close FH;
	my @temp=split("\n",$str);		
	for( my $i=0;$i<$header;$i++){
		push @head,$temp[$i] if ($#head<$header-1);
	}
	for(my $j=$header;$j<$#temp;$j++){
		push @body,$temp[$j];
	}
	my @footer = split(" ",$temp[$#temp]);
	for($k=0;$k<=$#footer;$k++){
		$foot[$k]=$foot[$k]+$footer[$k];
	}
}
print join "\n",@head;
print "\n",join "\n",@body;
print "\n",join " ",@foot;