Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi , 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
Based on above files, what i need is to print records if second field is not matching.Hence my record should contain:abc,,,, abc,10001781,,, abc,10001782,,, abd,10001783,,,
But it prints:abc,,,, abc,10001781,,, abc,10001782,,, abd,10001783,,,
Can anyone please guide me what is the bug in thi. Please find my code snippet below:abc,10001781,,, abc,10001782,,, abd,10001783,,,
... 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: grep in Perl
by Laurent_R (Canon) on Jun 05, 2015 at 13:16 UTC | |
|
Re: grep in Perl
by Tux (Canon) on Jun 05, 2015 at 13:32 UTC | |
|
Re: grep in Perl
by Anonymous Monk on Jun 05, 2015 at 09:18 UTC | |
by aaron_baugher (Curate) on Jun 05, 2015 at 12:12 UTC | |
by vinoth.ree (Monsignor) on Jun 05, 2015 at 10:45 UTC |