#!/usr/bin/env perl use strict; use warnings; my $first = shift; die "usage: ./script firstfile secondfile" unless $first; my $second = shift; die "usage: ./script firstfile secondfile" unless $second; my @first = `cat $first`; my @second = `cat $second`; my %first; foreach (@first) { chomp; $first{$_}++; } my %second; foreach (@second) { chomp; $second{$_}++; } # let's run through our list and see which of second is missing my $missingfromfirst = 'missingfromfirst.txt'; my $missingfromsecond = 'missingfromsecond.txt'; # ...zeroing out the files frist system ": > $missingfromfirst"; system ": > $missingfromsecond"; # which items are common to both lists? my $common = 'commonentries.txt'; system ": > $common"; my %common; # if we have an item and it's not in their list, they are we report it as their missing item system ": > $missingfromsecond"; foreach (@first) { chomp; system "echo $_ >> $missingfromsecond" unless $second{$_}; $common{$_}++; } system ": > $missingfromfirst"; foreach (@second) { chomp; system "echo $_ >> $missingfromfirst" unless $first{$_}; $common{$_}++; } foreach (keys %common) { system "echo $_ >> $common" if $common{$_} > 1; }