
saurabhsmahajan
New User
Dec 3, 2013, 3:14 PM
Post #1 of 6
(1946 views)
|
Finding a string from one file into another file
|
Can't Post
|
|
Hello Guys, I need help in searching for a string from one file into another file and printing it.I have two files "id.txt" and "path.txt". id.txt has values as below X34256 Y64375 Y32435 Y89756 X85263 and path.txt has values as below X34256_BULB_STR X34256_BUB_STR X34256_BULB_STR2 Y89756_ROD_INT Y89756_ROD_INT2 Now here I want to find all the values from file path.txt which would start with the value from id.txt Here is my program as below. But would print only one line and not iterating through the complete file. #use strict; use warnings; open DFH,'<',"D:\\perlprog\\id.txt" or die "Could not open file"; open VFH,'<',"D:\\perlprog\\path.txt" or die "Could not open file"; foreach (my $da=<DFH>) { chomp $da; print $da; while (<VFH>) { print $_ if(/$da/); } } Could you please help me solve this issue. Apologize if commiting any mistake as I am beginner. Thanks.
|