Skip to content

Instantly share code, notes, and snippets.

@emsearcy
Created July 9, 2019 21:09
Show Gist options
  • Save emsearcy/af3f3d8070c686371e42d475b4fda549 to your computer and use it in GitHub Desktop.
Save emsearcy/af3f3d8070c686371e42d475b4fda549 to your computer and use it in GitHub Desktop.
compare lines
#!/usr/bin/perl -W
open FILE_A, "<", $ARGV[0];
open FILE_B, "<", $ARGV[1];
my %a_lines = ();
my %b_lines = ();
my %a_only_lines = ();
my %b_only_lines = ();
my $both_lines = 0;
while (<FILE_A>) {
$a_lines{$_}++;
}
while (<FILE_B>) {
$b_lines{$_}++;
}
foreach $a_line (keys %a_lines) {
if (!(exists($b_lines{$a_line}))) {
# uncomment to show lines only in a
#print $a_line;
$a_only_lines{$a_line} = 1;
} else {
$both_lines++;
}
}
foreach $b_line (keys %b_lines) {
if (!(exists($a_lines{$b_line}))) {
# uncomment to show lines only in b
#print $b_line;
$b_only_lines{$b_line} = 1;
}
}
print "a only lines:\t";
print scalar(keys(%a_only_lines));
print "\n";
print "b only lines:\t";
print scalar(keys(%b_only_lines));
print "\n";
print "shared lines:\t$both_lines\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment