統計兩個文件中相同行的數目

#!/usr/bin/perl
#================================================================================================================
#Author:huangyunhao
#Date:2010-12-10
#Function:count the number of the same lines between two lines containing a IP every line and the IP number in every file.
#Usage:perl two_files_insect.pl <flie1> <file2>
#================================================================================================================
use strict;
use warnings;

my %hash;
my $line_n=0;
open(FILE,'<',$ARGV[0]) || die "Cannot open $ARGV[0]:$!";
while(<FILE>){
 $line_n++;
 chomp;
 $hash{$_}=1;
}
close FILE;
print "The IP number in the first file:$line_n/n";
$line_n=0;
my $number=0;
open(FILE,'<',$ARGV[1]) || die "Cannot open $ARGV[1]:$!";
while(<FILE>){
 $line_n++;
 chomp;
 $number++ if(exists $hash{$_});
}
close FILE;
print "The IP number in the second file:$line_n/n";
print "The number of same IP:$number/n";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章