Here's a script I posted a while ago, which generally does the sort of thing you're trying to do: cmpcol.

And here's what the usage might look like to have that script output the combined contents of lines from two files, where columns 1,2,3 of fileA match columns 2,3,4 of fileB (first column is #1):

cmpcol -i -lb tab fileA:1,2,3 fileB:2,3,4
Now, as a first try, the output will be more than you actually want: it prints the full content of both matching lines. (And if key columns are not unique within one of the files -- e.g. fileA has multiple lines with the same combination of values in columns 1,2,3 and these match a row in fileB -- you'll get multiple lines from that file that match a single line from the other file.)

But you can easily filter the output to trim out the unwanted columns. And maybe the "cmpcol" script itself will give you some ideas for how to write a script that does exactly what you want.


In reply to Re: Matching columns between files by graff
in thread Matching columns between files by gggg

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.