releasing version 0.4
[moreutils.git] / and
blob41654102ff5bb0c9684aab880bfa7359aa7b467d
1 #!/usr/bin/perl
3 =head1 NAME
5 and - print lines that are present in one file and another
7 =head1 SYNOPSIS
9 and file
11 and [file|-] [file|-] ...
13 =head1 DESCRIPTION
15 B<and> reads the specified files and prints out the lines that are common
16 to all files, in the order they are listed in the last file. Use "-" to
17 make it read a file from standard input. If only one file is specified,
18 B<and> first reads 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: and [file|-] [file|-] ...\n";
35 if (@ARGV == 1) {
36 unshift @ARGV, "-";
39 my %seen;
40 foreach my $fn (@ARGV) {
41 open (IN, $fn) || die "and: read $fn: $!\n";
42 while (<IN>) {
43 chomp;
44 $seen{$_}++;
45 if ($seen{$_} == @ARGV) {
46 print "$_\n";
49 close IN;