I have two files and I need to print the line from file1 that matches the part number in file2.
File1 looks like:
3478748:AA:1D:AAA:Descriptions:C:2
3478749:AA:1D:AAA:Descriptions:C:2
3633731:AA:3E:AAA:Descriptions:C:2
File2 looks like:
3478749
3633731

Currently it is printing all lines in File1

Output should be line in File1 that have string in File2 or:

3478749:AA:1D:AAA:ROCKER ARM ASSEMBLIES AND GROUPS:C:2
3633731:AA:3E:AAA:ROCKER ARM ASSEMBLIES AND GROUPS:C:2

<code> #!/usr/bin/perl
use Encode;
use strict;
use warnings;
require 'tools/csvutils.pl';
$|=1;
#open (OUTFILE, '>:crlf', 'final_lines.txt') or die 'Cannot open file';
#open parent file
open (FILE1, '<:crlf', 'file1.txt') or die 'Cannot open file';
#open child file
open (FILE2, '<:crlf', 'file2.csv') or die 'Cannot open file';
my @goodarray =<FILE2>;
while (my $line = <FILE1>) {
my @filerecord = $line;
for (@goodarray){
my $data = $_;
my @arrfields = $data;
chomp (@arrfields);
my $filedata =\@filerecord;
${$filedata}[0] =~ s/^\s+|\s+$//g;
$arrfields[0] =~ s/^\s+|\s+$|-//g;
#$arrfields[0] =~ s/-//g;
my $string = ${$filedata}[0];
if ($string =~ /(^\d{7,8})/ ){
my $substr = $1;
if (index($string, $substr) !=-1)
{
print "$string\n";
last;
}
}
}
}

In reply to extract line by lallison

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.