5 combine - combine sets of lines from 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> combines 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 in file1 if they are also present in file2.
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 occur in file1 (followed by the order they occur in file2 for the two
54 "or" operations). Bear in mind that this means that the operations are not
55 commutative; "a and b" will not necessarily be the same as "b and a". To
56 obtain commutative behavior sort and uniq the result.
58 Note that this program can be installed as "_" to allow for the syntactic
59 sugar shown in the latter half of the synopsis (similar to the test/[
60 command). It is not currently installed as "_" by default, but you can
61 alias it to that if you like.
69 Copyright 2006 by Joey Hess <joey@kitenet.net>
71 Licensed under the GNU GPL.
82 open (IN
, $file) || die "$file: $!\n";
94 filemap
$file, sub { $seen{$_}++ };
99 my ($file1, $file2) = @_;
101 filemap
$file1, sub { print "$_\n" };
102 filemap
$file2, sub { print "$_\n" };
106 my ($file1, $file2) = @_;
108 compare_not
($file1, $file2);
109 compare_not
($file2, $file1);
113 my ($file1, $file2) = @_;
115 my $seen=hashify
($file2);
116 filemap
$file1, sub { print "$_\n" unless $seen->{$_} };
120 my ($file1, $file2) = @_;
122 my $seen=hashify
($file2);
123 filemap
$file1, sub { print "$_\n" if $seen->{$_} };
126 if (@ARGV >= 4 && $ARGV[3] eq "_") {
131 die "Usage: combine file1 OP file2\n";
138 if ($::{"compare_$op"}) {
140 "compare_$op"->($file1, $file2);
143 die "unknown operation, $op\n";