本帖最后由 sxw 于 2011-10-30 20:40 编辑
用Perl写了下,比较粗糙,应该可以实现你的要求吧?- #!/usr/bin/perl
- #diff.pl
- #usage:perl diff.pl 1.txt 2.txt
- use strict;
- use warnings;
- my %hash;
- my @file;
- my $fh;
- open $fh,"<","1.txt" or die;
- @file=<$fh>;
- close $fh;
- my $fh_2;
- open $fh_2,"<","2.txt" or die;
- my @file_2=<$fh_2>;
- close $fh_2;
- push @file,@file_2;
- chomp @file;
- $hash{"$_"}++ for (@file);
- open FH,">","3.txt" or die;
- open F,">","4.txt" or die;
- for (keys %hash) {
- print $hash{$_},"\n";
- print FH "$_\n" if $hash{$_}==1;
- print F "$_\n" if $hash{$_}>1;
- }
复制代码
|