I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines).
Does anybody have an idea how to do that using perl, awk or sed?
Thank you so much in advance!
Iris
------------------------------------------------------------------------------
File A
------------------------------------------------------------------------------
-------------------------------------------------------------------------------
File B
-------------------------------------------------------------------------------
0000 N NNNNN N N CCCCC NNN 2
0001 P PPPPP P P CCCCC PPP 1
0002 P PPPPP P P CCCCC PPP 1
0003 P PPPPP P P CCCCC PPP 1
0004 N NNNNN N N CCCCC NNN 2
#!/usr/bin/perl
use strict;
my $fileA=shift;
my $fileB=shift;
my $fileR=shift;
open (FA,"<",$fileA ) || die "Can't open $fileA\n";
my @txtA=<FA>;
close(FA);
open (FB,"<",$fileB ) || die "Can't open $fileB\n";
my @txtB=<FB>;
close(FB);
open (FR,">",$fileR ) || die "Can't open $fileR\n";
my ($contA,$a,$contB,$b)=0;
for my $i ( 1 .. 40 ) {
for $a ( 1 .. 10 ) {
$a+=$contA;
print FR $txtA[$a];
}
$contA+=10;
for $b ( 1 .. 6 ) {
$b+=$contB;
print FR $txtB[$b];
}
$contB+=6;
}
close(FR);
exit;