Try reading the b file first and then match the words to those in a
poj#!/usr/bin/perl use strict; use Data::Dumper; my %file2 = (); open FILE2,'<',"./b.txt" or die "Cannot open b.txt"; while (<FILE2>){ my @words = split /\s+/,$_; my $zz = join 'zz',@words; for (@words){ $file2{$_} = $zz; } } close FILE2; print Dumper \%file2; open FILE1,'<',"./a.txt" or die "Cannot open a.txt"; open FILE3,'>',"./r.txt" or die "Cannot create r.txt"; while (<FILE1>){ chomp; my @words = split /[ \.]/,$_; my @added; for (@words){ push @added,$file2{$_} if exists $file2{$_}; }; print FILE3 $_,(join ' ',@added),"\n"; } close FILE1; close FILE3;
In reply to Re: Insert and attach sequence of words in txt file if it exist in other file
by poj
in thread Insert and attach sequence of words in txt file if it exist in other file
by shoura
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |