Start New Discussion Reply to this Discussion matching and replacing characters of 2 files
I have 2 file
File1
1. amayaM
2. vismayaM
3. vismayaN
File2
1. amayamAn
2. vismayamAn
3. vismayamer
I need to check each character by character between 2 files and if the nonmatching character in first file is M then print the word in first file else no output.
output
1. amayaM
2. vismayaM
Related Article: Compare 2 Files
is a Perl discussion thread by Aditya_MUHAHA that has 1 reply and was last updated 7 months ago.
laksraju
Newbie Poster
2 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Hi laksraju,
Please could you show what you have done so far. The area of the code where you are having problems. Writing the code for you would not help you in the long run.
Secondly,you might look into the archieve of this forum. This kind of problem has been solved again and again. You can adapt one of the solved problems for your usage. And if you are still having problems, then come back we will be able to help.
thanks,
2teez
2teez
Junior Poster
162 posts since Apr 2012
Reputation Points: 40
Solved Threads: 32
Skill Endorsements: 0
the code was done like this
use warnings;
use strict;
open my $fh1, '<', 'first_file.txt' or die $!;
open my $fh2, '<', 'second_file.txt' or die $!;
while ( my $s1 = <$fh1> ) {
chomp $s1;
chomp( my $s2 = <$fh2> );
( $s1 ^ $s2 ) =~ /[^\x00]/;
substr( $s2, $-[0], 0 ) ='M' if defined $-[0];
print $s2, "\n";
}
close $fh2;
close $fh1;
laksraju
Newbie Poster
2 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Hi laksraju,
You apprently, didn't understand the solution to a similar question, you posted on Perlmonks and the solution given to you by Kenosis.
2teez
Junior Poster
162 posts since Apr 2012
Reputation Points: 40
Solved Threads: 32
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0620 seconds
using 2.64MB