in reply to Re: Compare 2 files and create a new one if it matches
in thread Compare 2 files and create a new one if it matches
#!/usr/bin/perl use strict; use warnings; use Regexp::List qw( ); my $File1 = '...'; my $File2 = '...'; my $File3 = '...'; my $keep_re; { open(my $fh_keys, '<', $File1) or die("Can't open key file \"$File1\": $!\n); $keep_re = Regexp::List ->new() ->list2re( map { my $s = $_; chomp($s); $s } <$fh_keys> ); } { open(my $fh_in, '<', $File2) or die("Can't open input file \"$File2\": $!\n"); open(my fh_out, '>', $File3) or die("Can't create output file \"$File3\": $!\n"); print $fh_out grep /^[^|]*\|$keep_re\|/, <$fh_in>; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Compare 2 files and create a new one if it matches
by swampyankee (Parson) on Sep 23, 2008 at 01:50 UTC | |
by ikegami (Patriarch) on Sep 23, 2008 at 02:05 UTC |