freakpea has asked for the wisdom of the Perl Monks concerning the following question:
Hi Guys Sorry a bit new to this so struggling a bit I have a data file with strings that I need to search for in another file. At the moment the match is for the whole line but I would like to change it that the match is that the data can match a piece of the line
DATA file
hostname banner exec search file hostname XXXXX banner exec ********************************************************** +******************** banner exec banner exec This device belongs to the
Here is my code below
use strict; use warnings; my %file2; open my $file2, '<', shift or die; while ( my $line = <$file2> ) { ++$file2{$line}; } open my $file1, '<', shift or die; while ( my $line = <$file1> ) { print $line unless $file2{$line}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching string from one file in another
by hippo (Archbishop) on Feb 28, 2017 at 13:25 UTC | |
by Eily (Monsignor) on Feb 28, 2017 at 13:35 UTC | |
|
Re: searching string from one file in another
by Eily (Monsignor) on Feb 28, 2017 at 13:29 UTC | |
by BillKSmith (Monsignor) on Feb 28, 2017 at 17:36 UTC | |
by stray_tachyon (Initiate) on Aug 17, 2018 at 14:43 UTC | |
by Eily (Monsignor) on Aug 17, 2018 at 15:16 UTC |