I am new to perl scripting. I have 2 new input files, file1 and file2. I have to retrieve second field of each record from first file and check if it is existing in second file, file2. I have read file2 contents and stored it in an array. Please find my file2(npn.txt) contents below:
11111111
10001781
11111222
File1 contents:
abc,,,,
abc,10001781,,,
abc,10001782,,,
abd,10001783,,,
Based on above files, what my record should contain:
abc,,,,
abc,10001782,,,
abd,10001783,,,
But it prints:
abc,10001781,,,
abc,10001782,,,
abd,10001783,,,
Can anyone please guide me what is the bug in this. Please find my code snippet below:
...
open (info, "<npn.txt");
chomp (@contents = (<info>));
close info;
$record = $_."~";
@flds = split(/\,/, $record);
if (grep !/^$flds[1]/, @contents) {
print $record;
}
' >hi5res.txt