From 6a7f34809e87a940cd30c7e9de160db4ee9e65ca Mon Sep 17 00:00:00 2001 From: joeyh Date: Mon, 6 Mar 2006 03:33:23 +0000 Subject: [PATCH] releasing version 0.4 --- Makefile | 4 ++-- README | 17 +++++------------ and | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 7 +++++++ debian/control | 3 +++ debian/copyright | 2 +- not | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 125 insertions(+), 15 deletions(-) create mode 100755 and create mode 100755 not diff --git a/Makefile b/Makefile index 5e67318..d950595 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README b/README index 6b0ea37..96c5222 100644 --- a/README +++ b/README @@ -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 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; +} 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 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 diff --git a/not b/not new file mode 100755 index 0000000..c67467c --- /dev/null +++ b/not @@ -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 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 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: 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 () { + chomp; + $seen{$_}++; + } + close IN; +} + + +open (IN, $first) || die "and: read $first: $!\n"; +while () { + chomp; + print "$_\n" if ! $seen{$_}; +} +close IN; -- 2.11.4.GIT