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:
File1 contents:11111111 10001781 11111222
abc,,,, abc,10001781,,, abc,10001782,,, abd,10001783,,,
Based on above files, what my record should contain:
But it prints:abc,,,, abc,10001782,,, abd,10001783,,,
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
In reply to Re: grep in Perl
by Anonymous Monk
in thread grep in Perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |