in reply to Insert and attach sequence of words in txt file if it exist in other file
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Insert and attach sequence of words in txt file if it exist in other file
by shoura (Novice) on May 13, 2017 at 20:35 UTC | |
by poj (Abbot) on May 13, 2017 at 20:40 UTC | |
by shoura (Novice) on May 13, 2017 at 20:44 UTC | |
by poj (Abbot) on May 13, 2017 at 20:48 UTC | |
by shoura (Novice) on May 13, 2017 at 21:47 UTC | |
|