Here's a basic idea of how I might approach this problem.
- Open 1.txt and read its contents into a data structure suitable for later use.
- Process each line of 2.txt. Change the line based on the data read in step 1, and write it to a third file.
- When processing of 2.txt is complete, rename the third file to 2.txt
Example of step 1:
my %new_pass;
while (<F1>) {
chomp;
my @f = split(':', $_);
$new_pass{$f[0]} = $f[2];
}
Example of step 2:
while (<F2>) {
chomp;
my @f = split(':', $_);
if (exists $new_pass[$f[0]]) {
$f[1] = $new_pass[$f[0]];
}
print F3 join(':', @f), "\n";
}
|