in reply to how to find common and not common lines in 2 files?
use strict; use warnings; my %in_files; open(my $f1, '<', 'FILE1') or die "can't open FILE1: $!\n"; while (<$f1>) { $in_files{$_} .= '1'; } open(my $f2, '<', 'FILE2') or die "can't open FILE2: $!\n"; while (<$f2>) { $in_files{$_} .= '2'; } open(my $common, '>', 'common_lines') or die "can't open common_lines: + $!\n"; open(my $u1, '>', 'unique_1') or die "can't open unique_1: $!\n"; open(my $u2, '>', 'unique_2') or die "can't open unique_2: $!\n"; for (keys %in_files) { if ($in_files{$_} =~ m/12/) { print $common $_ } else if ($in_files{$_} =~ m/1/) { print $u1 $_ } else { print $u2 $_ } }
|
|---|