If you edit your post and put <code> tags around your data, as you did with your code in your first post in this thread, we'll be able to read it.

Okay, it sounds like you have a fairly typical "match lines from fileA to lines in fileB" problem, with the added feature of needing to match three fields instead of just one. So the standard solution is to go through one file (usually the smaller one to keep memory use lower), creating a hash of keys with the important fields from that file, then go through the other file line-by-line, checking each line to see if its fields are found in the hash. In pseudo-code:

create a %hash open fileA while get a line from fileA parse out the three important fields from the line concat those fields into a single string put that string in the hash as a key, with the line as its value close fileA open fileB while get a line from fileB parse out the three important fields from this line concat those fields into a single string if that string exists as a key in the hash print out this line and the value of the matching hash key close fileB

One caveat: this only works if the keys created from fileA are unique. If it's possible for multiple lines to have the same key (the same first three column values), you'll have to get a bit more complicated.

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.


In reply to Re^4: Compare three columns of one file with three columns of another file in perl by aaron_baugher
in thread Compare three columns of one file with three columns of another file in perl by anonym

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.