统计两个文件中相同行的数目

来源:互联网 发布:jy网络上是什么意思 编辑:程序博客网 时间:2024/04/29 19:22

#!/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";

原创粉丝点击