Assitance needed in checking file difference using a perl script
Below is the example
I wanted a report saying file2 has an update of new value.
File1 old date
Alpha 156
Beta 255
Gama 6987
segma 4578
File2 new date
Alpha 156
Beta 255
Gama 1000
segma 4578
Result
File2 has an update
Gama 1000
Yoda
2
Here is a solution using awk
program:
awk 'NR==FNR{A[$1]=$2;next}$1 in A&&$2!=A[$1]' file1 file2
Disregard if you are looking for a perl
solution.
I have a perl script so i want to add the below step in perl .
Use hashes %_1 and %_2 with their members. Fill %_3. Report from %_3.
use strict ;
my $infile1 = q[File1];
my $infile2 = q[File2];
my %_1 = () ;
my %_2 = () ;
my %_3 = () ;
#now firstfill...
open (I, '<' . $infile1) or die @! ;
open (II, '<' . $infile2) or die @! ;
while (<I>) {
chomp ;
m/^(.+?)\s+([0-9\+\-]+)$/ ;
$_1{$1} = $2 ;
m/./; #reset regex
}
while (<II>) {
m/./ ; #reset regex
chomp ;
m/^(.+?)\s+([0-9\+\-]+)$/ ;
$_2{$1} = $2 ;
}
#fill....
push %_3, map { ($_, $_2{$_}) } grep { $_1{$_} != $_2{$_} } keys %_2 ;
#now report ...
print qq[\n], $_, qq[\t\t], $_3{$_} for sort keys %_3 ;