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)
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
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
--- /dev/null
+#!/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;
+}
+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.
- 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
+
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
--- /dev/null
+#!/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;