Hello all, I've been working on a project for the past week or so and have gotten stumped on this step. It's easier to explain with an example so here it is...

There are two input files, an ID file of 3 columns and a Name file of four columns (the actual data are large ~ 100,000 rows):

ID file:
ID Catg_ID Pos
12 A 16
15 B 5
16 A 175

Name file:
Catg_Name Start Stop Name
A 8 19 jamm
A 110 112 bbc
E 170 256 vadd
A 14 18 cip

For each row in the ID file, I need to compare the Catg_ID variable to the Catg_Name variable in the Name file. Then, if the catg variables match, I want to see if Pos is between Start and Stop. For rows that meet both the above criteria, I want to combine them in a single output file.

So, to recap, IF Catg_ID = Catg_Name AND Pos > Start AND Pos < Stop I want to print "ID Catg_ID Pos Name"

And just to be clear, I need to compare not the first line in the ID file to the first line in the name file, but the first line in the ID file to every line in the name file, then the second line in the ID file to every line in the name file, and so on. Multiple matches are fine.

For the above data, I would want the program to print:
12 A 16 jamm
12 A 16 cip

Thanks in advance. I've tried to be as clear and specific as possible.


In reply to Comparing multiple entries from two files by hanger4

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.