Advertisement
Guest User

Untitled

a guest
May 10th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.76 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict ;
  4. use warnings ;
  5. use Data::Dumper ;
  6.  
  7. my ($file2,$file1,$output) = (@ARGV,"output_comp") ;
  8. my (%hash,%tmp) ;
  9.  
  10. (scalar @ARGV != 2 ? (print "Need 2 files!\n") : ()) ? exit 1 : () ;
  11.  
  12. for (@ARGV) {
  13.   open FH, "<$_" || die "Cannot open $_\n" ;
  14.   while (my $line = <FH>){$line =~ s/^.+[()].+$| +?$//g ; chomp $line ; $hash{$_}{$line} = "$line"}
  15.   close FH ;}
  16.  
  17. open FH, ">>$output" || die "Cannot open outfile!\n" ;
  18. foreach my $k1 (keys %{$hash{$file1}}){
  19.   foreach my $k2 (keys %{$hash{$file2}}){
  20.     if ($k2 =~ m/^.+?$k1.+?$/i){    # Case Insensitive matching.
  21.       if (!defined $tmp{"$hash{$file2}{$k2}"}){
  22.         print FH "$hash{$file2}{$k2}\n" ;
  23.         $tmp{"$hash{$file2}{$k2}"} = 1 ;
  24.                 }}}} close FH  ;
  25. # End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement