releasing version 0.4
[moreutils.git] / not
blobc67467c17a33fbb679bf900b959b0a9b866e299d
1 #!/usr/bin/perl
3 =head1 NAME
5 not - print lines that are present in one file but not another
7 =head1 SYNOPSIS
9 not file
11 not [file|-] [file|-] ...
13 =head1 DESCRIPTION
15 B<not> reads the specified files and prints out the lines that are present
16 in the first but not in subsequent files. Use "-" to make it read a file
17 from standard input. If only one file is specified, B<not> first reads
18 standard input, and compares it with the specified file.
20 =head1 AUTHOR
22 Copyright 2006 by Joey Hess <joey@kitenet.net>
24 Licensed under the GNU GPL.
26 =cut
28 use warnings;
29 use strict;
31 if (@ARGV == 0) {
32 die "usage: not [file|-] [file|-] ...\n";
35 if (@ARGV == 1) {
36 unshift @ARGV, "-";
39 my $first=shift;
41 my %seen;
42 foreach my $fn (@ARGV) {
43 open (IN, $fn) || die "and: read $fn: $!\n";
44 while (<IN>) {
45 chomp;
46 $seen{$_}++;
48 close IN;
52 open (IN, $first) || die "and: read $first: $!\n";
53 while (<IN>) {
54 chomp;
55 print "$_\n" if ! $seen{$_};
57 close IN;