diff options
author | joeyh <joeyh> | 2006-03-06 03:33:23 +0000 |
---|---|---|
committer | joeyh <joeyh> | 2006-03-06 03:33:23 +0000 |
commit | 6a7f34809e87a940cd30c7e9de160db4ee9e65ca (patch) | |
tree | 373ce8f5df8986dba781ec07635d797598449407 | |
parent | 31bab120cc259d70b3706dbd7210159b4667171d (diff) | |
download | moreutils-6a7f34809e87a940cd30c7e9de160db4ee9e65ca.tar.gz |
releasing version 0.40.4
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | README | 17 | ||||
-rwxr-xr-x | and | 50 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | debian/control | 3 | ||||
-rw-r--r-- | debian/copyright | 2 | ||||
-rwxr-xr-x | not | 57 |
7 files changed, 125 insertions, 15 deletions
@@ -1,6 +1,6 @@ BINS=isutf8 sponge -PERLSCRIPTS=vidir vipe ts -MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 +PERLSCRIPTS=vidir vipe ts and not +MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 and.1 not.1 CFLAGS=-O2 -g -Wall all: $(BINS) $(MANS) @@ -11,6 +11,11 @@ vidir edit a directory in your text editor vipe edit a pipe using your text editor +and + print lines that are present in one file and another +not + print lines that are present in one file but not another + Your suggestions of additional tools to add to this collection are apprecitated. Here are some that are under consideration but have not yet @@ -27,18 +32,6 @@ ifcfg http://edgard.dyn.fdn.fr/developpements/ifcfg.shtml (Tarball link 404 when last checked.) -and - filter a stream for the entries that exist in another file - http://arstechnica.com/articles/columns/linux/linux-20050822.ars - - (Isn't there a way to do this with standard unix tools?) - -not - filter a stream for the entries that do not exist in another file - http://arstechnica.com/articles/columns/linux/linux-20050822.ars - - (Isn't there a way to do this with standard unix tools?) - z makes another program understand compressed files ex: z zxgv file.bmp.gz @@ -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<and> 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<and> first reads standard input, and compares it with the specified file. + +=head1 AUTHOR + +Copyright 2006 by Joey Hess <joey@kitenet.net> + +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 (<IN>) { + chomp; + $seen{$_}++; + if ($seen{$_} == @ARGV) { + print "$_\n"; + } + } + close IN; +} diff --git a/debian/changelog b/debian/changelog index cbec1db..7777952 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +moreutils (0.4) unstable; urgency=low + + * Added versions of and(1) and not(1) that support arbitrary numbers of + input files. + + -- Joey Hess <joeyh@debian.org> Sun, 5 Mar 2006 22:28:13 -0500 + moreutils (0.3) unstable; urgency=low * Switch sponge to a C implementation by mithandir. diff --git a/debian/control b/debian/control index 4685379..1a98b9e 100644 --- a/debian/control +++ b/debian/control @@ -18,3 +18,6 @@ Description: additional unix utilities - ts: timestamp standard input - vidir: edit a directory in your text editor - vipe: edit a pipe using your text editor + - and: print lines that are present in one file and another + - not: print lines that are present in one file but not another + diff --git a/debian/copyright b/debian/copyright index dc62378..6718bac 100644 --- a/debian/copyright +++ b/debian/copyright @@ -5,7 +5,7 @@ isutf8 is Copyright (C) 2005 by Lars Wirzenius, under the terms of the GPL. spong is Copyright (C) 2006 by Tollef Fog Heen, under the terms of -the GPL version 2. +the GPL version 2. Name and concept by Colin Watson. Everything else is copyright 2006 by Joey Hess, under the terms of GPL. The full text of the GNU GPL can be found in /usr/share/common-licenses/GPL @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +=head1 NAME + +not - print lines that are present in one file but not another + +=head1 SYNOPSIS + +not file + +not [file|-] [file|-] ... + +=head1 DESCRIPTION + +B<not> reads the specified files and prints out the lines that are present +in the first but not in subsequent files. Use "-" to make it read a file +from standard input. If only one file is specified, B<not> first reads +standard input, and compares it with the specified file. + +=head1 AUTHOR + +Copyright 2006 by Joey Hess <joey@kitenet.net> + +Licensed under the GNU GPL. + +=cut + +use warnings; +use strict; + +if (@ARGV == 0) { + die "usage: not [file|-] [file|-] ...\n"; +} + +if (@ARGV == 1) { + unshift @ARGV, "-"; +} + +my $first=shift; + +my %seen; +foreach my $fn (@ARGV) { + open (IN, $fn) || die "and: read $fn: $!\n"; + while (<IN>) { + chomp; + $seen{$_}++; + } + close IN; +} + + +open (IN, $first) || die "and: read $first: $!\n"; +while (<IN>) { + chomp; + print "$_\n" if ! $seen{$_}; +} +close IN; |