From 6a7f34809e87a940cd30c7e9de160db4ee9e65ca Mon Sep 17 00:00:00 2001 From: joeyh Date: Mon, 6 Mar 2006 03:33:23 +0000 Subject: releasing version 0.4 --- and | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 and (limited to 'and') diff --git a/and b/and new file mode 100755 index 0000000..4165410 --- /dev/null +++ b/and @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +=head1 NAME + +and - print lines that are present in one file and another + +=head1 SYNOPSIS + +and file + +and [file|-] [file|-] ... + +=head1 DESCRIPTION + +B reads the specified files and prints out the lines that are common +to all files, in the order they are listed in the last file. Use "-" to +make it read a file from standard input. If only one file is specified, +B first reads standard input, and compares it with the specified file. + +=head1 AUTHOR + +Copyright 2006 by Joey Hess + +Licensed under the GNU GPL. + +=cut + +use warnings; +use strict; + +if (@ARGV == 0) { + die "usage: and [file|-] [file|-] ...\n"; +} + +if (@ARGV == 1) { + unshift @ARGV, "-"; +} + +my %seen; +foreach my $fn (@ARGV) { + open (IN, $fn) || die "and: read $fn: $!\n"; + while () { + chomp; + $seen{$_}++; + if ($seen{$_} == @ARGV) { + print "$_\n"; + } + } + close IN; +} -- cgit v1.2.3