5 combine - combine the lines in two files using boolean operations
9 combine file1 and file2
11 combine file1 not file2
13 combine file1 or file2
15 combine file1 xor file2
27 B<combine> conbines the lines in two files. Depending on the boolean
28 operation specified, the contents will be combined in different ways:
34 Outputs lines that are common to both files.
38 Outputs lines that are in file1 but not in file2.
42 Outputs lines that are in file1 or file2.
46 Outputs lines that are in either file1 or file2, but not in both files.
50 "-" can be specified for either file to read stdin for that file.
52 The input files need not be sorted, and the lines are output in the order
53 they accur in file1 (or file2 for the two "or" operations).
55 Note that this program can be installed as "_" to allow for the syntactic
56 sugar shown in the latter half of the synopsis (similar to the test/[
57 command). It is not currently installed as "_" by default, but you can
58 alias it to that if you like.
62 Copyright 2006 by Joey Hess <joey@kitenet.net>
64 Licensed under the GNU GPL.
75 open (IN
, $file) || die "$file: $!\n";
87 filemap
$file, sub { $seen{$_}++ };
92 my ($file1, $file2) = @_;
95 filemap
$file1, sub { print "$_\n"; $seen->{$_}++ };
96 filemap
$file2, sub { print "$_\n" unless $seen->{$_} };
100 my ($file1, $file2) = @_;
102 compare_not
($file1, $file2);
103 compare_not
($file2, $file1);
107 my ($file1, $file2) = @_;
109 my $seen=hashify
($file2);
110 filemap
$file1, sub { print "$_\n" unless $seen->{$_} };
114 my ($file1, $file2) = @_;
116 my $seen=hashify
($file2);
117 filemap
$file1, sub { print "$_\n" if $seen->{$_} };
120 if (@ARGV >= 4 && $ARGV[3] eq "_") {
125 die "usage: combine file1 OP file2\n";
132 if ($::{"compare_$op"}) {
134 "compare_$op"->($file1, $file2);
137 die "unknown operation, $op\n";