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"; }

In reply to Merging multiple files by bluray

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.