Ok so lets say I have two files that are tab delimited. The file1 has 20 columns, the first column is the gene. I have a file2 who's first column is also Gene(albeit in a different order), but the second column of file2 is a value that is not in the file1. Is there a faster way to add the file2 second column to the 21st column of file1 then reading in both as arrays and matching the Gene column, then printing out the variables that I have split respective columns into? A command line command would be preferable because the files layout are always changing.. and thus a script must be continuously altered based on splitting... here is an example script
#!/usr/bin/perl -w use strict; open(FILE,"$ARGV[0]"); my @input=<FILE>; close(FILE); foreach my $line(@input){ chomp $line; my @batch=(); (my $gene, my $VAA, my $ CCDS ,my $chrposMut, my $o_acc, my $o_pos +, my $o_aa1, my $o_aa2)= split(/\t/,$line); (my $chrpos,my $Mut)=split(/\./,$chrposMut); my ($chr,$position)=split(/\:/,$chrpos); my $vAA=$o_aa1 . $o_pos . $o_aa2; $vAA=~s/\s//g; @batch=`perl -ne 'print if /$position/' Gene_Asign.txt`; # put the + text file here that contains the gene name as well as something that + can be used to identify the correct row when comparing it with the p +olyphen outfile foreach my $Line(@batch) { chomp $Line; # (my $snp, my $str, my $gene, my $v4, my $v5, my $CCDS)=split( +/\t/,$Line); #print $Line ."\n"; my($Sample,$v2)= split(/\s/,$Line); #if($AA=~m/$vAA/){ print $Sample . "\t" . $line . "\n"; # print $gene . "\t" . $vAA . "\t" . $CCDS. "\t" . $line . "\n" +; # } } }

In reply to Adding a particular column from one file to a second file by ZWcarp

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.