I have two huge files. File1 has one column and File2 has two columns as follows:

File1

ABCD12

XYZ13

EFGT45

UVWZ34

TSR78

........

File2

ID121 ABC14

ID122 EFG87

ID145 XYZ43

ID157 TSR11

ID181 ABC31

ID962 YTS27

ID529 EFG56

ID684 TSR07

ID921 BAMD80

.............

I want to match first column of File1 and starting three alphabets of second column of File2 and print Ids of those are matched.

Desired output:

ID121 ABC14

ID122 EFG87

ID145 XYZ43

ID157 TSR11

ID181 ABC31

ID529 EFG56

ID684 TSR07

I tried foloowing code:

#!/usr/bin/perl use strict; use warnings; my ($f1,$f2,@patterns,%patts,$f2_rec,$f2_field); $f1 = $ARGV[0]; $f2 = $ARGV[1]; open(PATT,"<", $f1) or die; @patterns = <PATT>; chomp(@patterns); close(PATT) or die; @patts{@patterns} = (1) x @patterns; open(FILE,"<", $f2) or die; while (defined ($f2_rec = <FILE>)) { chomp $f2_rec; $f2_field = (split(/ /,$f2_rec))[0]; if(exists($patts{$f2_field})) { print "$f2_rec\n"; } } close(FILE) or die;

It know it won't separate matching initial three alphabets, but it will match exact values with 'error: use of unitialized value' until use warnings is blocked. Please help.


In reply to print all data matching identical three alphabets from two different files by mao9856

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.