Hi Monks who are always smarter than me! I am trying to compare 2 CSV files for Names/and or Company Names that the two have in common and return the complete lines in both if there is a match. I have a script that matches lines in each file and returns lines but I want to match on a string level as opposed to a line level that I've noted above. Here's my script, any guidance on how to modify is greatly appreciated!!

use strict; use warnings; use autodie; my $f1 = shift || "/opt/test.txt"; my $f2 = shift || "/opt/test1.txt"; my %results; open my $file1, '<', $f1; while (my $line = <$file1>) { $results{$line} = 1 } open my $file2, '<', $f2; while (my $line = <$file2>) { $results{$line}++ } foreach my $line (sort { $results{$b} <=> $results{$a} } keys %results +) { print "$results{$line}:", $line if $results{$line} >1;}

In reply to compare 2 CSV files for string return lines in both if match by Anonymous Monk

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.