Hi,
I have four files to merge. There is no overlap between the IDs (4th column) in each of these files. I can utilize 'cat', but the header will be repeated. Any help would be appreciated.
data
SP GC DC ID Descr GI Locus LF
cat Ts All 5320 CGA1 1892 L2 3.1
dog Ts Sp 6420 beta 1 1849 L3 4.2
------------------------------------
The format of the data is the same in the four files.
I am trying to write a code for this. I was not sure whether to create a hash for this. I am pasting the code below that I wrote. The code is not complete.
#!/usr/bin/perl -w
use strict;
use warnings;
my $infile1="file1.csv";
my $infile2="file2.csv";
my $infile3="file3.csv";
my $infile4="file4.csv";
open (my $in_fh1, "<", $infile1) or die "Can't open $infile1" ($!);
open (my $in_fh2, "<", $infile2) or die "Can't open $infile2" ($!);
open (my $in_fh3, "<", $infile3) or die "Can't open $infile3" ($!);
open (my $in_fh4, "<", $infile4) or die "Can't open $infile4" ($!);
open (my $out_fh, ">", "file1_4.csv");
while (defined(my $line1=<$in_fh1>) || defined (my $line2=<$in_fh2)||
+defined (my $line3=<$in_fh3)|| defined (my $line4=<$in_fh4)
){
chomp $line1;
$line1=~s/\t/,/g;
my @columnheadings=split (/\t/, $line1);
my $headings=join(",", @columnheadings);
chomp $line2;
$line2=~s/\t/,/g;
chomp $line3;
$line3=~s/\t/,/g;
chomp $line4;
$line4=~s/\t/,/g;
print $out_fh "$headings\n";
}