in reply to grep in Perl
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep in Perl
by aaron_baugher (Curate) on Jun 05, 2015 at 12:12 UTC | |
|
Re^2: grep in Perl
by vinoth.ree (Monsignor) on Jun 05, 2015 at 10:45 UTC |