|
#!/bin/perl
sub usage { return <<EOL;
usage: jsame file1 file2
display number of same lines between file1 and file2.
EOL
}
if($#ARGV<1) { print &usage(); exit 1;}
open(F1,"$ARGV[0]")||die("Can't open $ARGV[0]\n");
open(F2,"$ARGV[1]")||die("Can't open $ARGV[1]\n");
my ($n,$n1,$n2)=(0,0,0);
while((my $aline=<F1>)&&($n1=$n1+1)&&(my $bline=<F2>)&&($n2=$n2+1)) {
if($aline ne $bline) { &bye($n,$n1,$n2);}
$n++;
}
&bye($n,$n1,$n2);
sub bye {
my ($n,$n1,$n2)=@_;
while((my $aline=<F1>)&&($n1=$n1+1)) { }
while((my $bline=<F2>)&&($n2=$n2+1)) { }
if(($n==$n1)&&($n==$n2)) { print "SAME: $ARGV[0] $ARGV[1] :same in $n lines\n";}
else { print "DIFF: $ARGV[0] $ARGV[1] :same in $n lines out of $n1,$n2\n";
exit 0;
} |
|