I beg your monkness with a basic problem. I have two text files:
<file#1>
applebananapearcarrotcarrotbeardeerdeer goatcowduckswanchickenmouseratbirdmouse chocolatedogdogfishmousecatdeerbird newyorkcalifornianewjerseymousecatdeerbird
<file#2>
monksbicyclewindbikecars computercomputerprinters hellicopterairplaneshelf chocolatedogdogfishmouse printerprintermousecouch . . goes on for another 600,000 lines
The output should be:
catdeerbird
Which is the 3rd line in <File#1> and the 4th line of <File#2>.
I anticipate that there will be several thousand lines that will partially match. For any line which both files share the first 24 characters (they match) and thus I want to output after the 24 characters for those particular lines of <File#1>.

I did supersearch, talked on CB and asked if I could temporarily mask for <File#1> after the 24th character and once it then matches with a line inside <File#2> it would print out those masked characters. Anno said I should implement substr. I have put together a basic version but obviously I really need help with this.
#!/usr/bin/perl -w use strict; my %lines; my %lines2; my $str2; open(UNIQUES,"<$ARGV[0]"); open(ALL, "<$ARGV[1]"); while (<UNIQUES>) { $lines{$str1} = 1; } while (<ALL>) { print $str1 if substr( $str1, 0, 24) eq ($str2); next ($str2); }

Thank you for your kind assistance. Perl Monks Rule!

In reply to Compare Partial Lines of 2 Text Files by Knoperl

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.