Similar to the above posts but with very slight difference.
use strict; use warnings; use Data::Dumper; open ( my $fh2, '<', 'file2.txt') or die ("cannot open file1: $!"); my %test; while(my $line = <$fh2> ){ chomp $line; my( $part1, $part2) = split(/_/, $line); $test{$part1} = $part2; } close $fh2; open ( my $fh1, '<', 'file1.txt') or die ( "Cannot open the file2: $!" +); my @file1; while (my $line = <$fh1>) { chomp $line; push @file1, split /,/, $line; } close $fh1; open(my $wh, '>', 'file3.txt') or die ( "cannot open file2 to write: $ +!"); for my $file1 (@file1) { if (exists $test{$file1}) { print $wh join("_", ($file1, $test{$file1}."\n" )); } } close $wh;
In reply to Re: search contents of one file and replace with contents of another to make a new file
by lonewolf28
in thread SOLVED!!!: search contents of one file and replace with contents of another to make a new file
by vcorby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |