in reply to Adding a particular column from one file to a second file

You have two tab-delimited data files. They have a common key in their leftmost columns. You need to join the data in the two flat-file database tables (i.e., the two tab-delimited text files). You need an easily-configured command-line utility.

Use the join utility. Based on your description of your problem and your needs, there's no good reason to reinvent the join utility in Perl.

The command may be as simple as this:

    join -t '<tab>' file1.txt file2.txt > file3.txt

Come join us on JoinMonks.org! ;-)

Jim

Replies are listed 'Best First'.
Re^2: Adding a particular column from one file to a second file
by ZWcarp (Beadle) on Jul 15, 2011 at 17:09 UTC
    Excellent!! what a useful thing to know. Ok this is probably a dumb question but why is it telling me
    join -t '\t' -a1 -1 16 -2 2 PTCL_All.txt Cosmic_Counts_By_Gene.txt join: illegal tab character specification <\code> or <code>join -t '<tab>' -a1 -1 16 -2 2 PTCL_All.txt Cosmic_Counts_By_ +Gene.txt join: illegal tab character specification
    Isn't -t ' CHAR' the correct format for specifying the delimiter in the output? Also if I use join  -t ',' -a1 -1 16 -2 2   PTCL_All.txt Cosmic_Counts_By_Gene.txt The output seems to be much more different than just a comma delimeter being added to the command  join   -a1 -1 16 -2 2   PTCL_All.txt Cosmic_Counts_By_Gene.txt Am I doing this correctly? the latter just looks like what I want with spaces separating the columns( the same number of lines as file 1), while the former seems to create a million repeats of each line (many many many more lines than what is in either file).
      I think this works though.... join   -a1 -1 16 -2 2   PTCL_All.txt Cosmic_Counts_By_Gene.txt |perl -pe 's/ /\t/g'