This code will create a new file; only, if there is any new records in the "file2".
Regards,#!/usr/bin/perl -w use strict; open FIRST,"file1" or die "Can't open file1: $!\n"; open LAST,"file2" or die "Can't open file2: $!\n"; my ( $Flag, @Last, @First, %Hash ); chomp ( @First = <FIRST> ); chomp ( @Last= <LAST> ) ; $Flag = 0; foreach my $record ( @First ) { $record =~/^(\S*) (\d*)$/; $Hash{$1} = $2 ; } foreach my $record ( @Last ) { $record =~ /^(\S*) (\d*)$/; unless ( exists $Hash{$1} ) { $Flag++; $Hash{$1} = $2; } } if ( $Flag ) # This condition checking avoids unwanted creatio +n of the new file. Hope it will add value to the code. { open NEW,">file3" or die "Can't open file3: +$!\n"; map { print NEW "$_ $Hash{$_}\n"} sort keys +%Hash ; close NEW; } close FIRST; close LAST;
In reply to Re: file compare and populate
by vennirajan
in thread file compare and populate
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |