does a zgrep exist? (zgrep <> zcat | grep)

Mark Brader msb at sq.sq.com
Wed Feb 20 14:21:44 AEST 1991


Here's what I use.  I place it in the public domain; use at your own risk.
You should insert a PATH= line to suit your system.  This program runs any
of grep, egrep, or fgrep, if it is linked as zgrep, zegrep, and zfgrep
respectively.  Unlike zcat, it will *not* accept "foo" as a synonym for
"foo.Z"; nor will it allow compressed and non-compressed files to be mixed.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  zgrep
# Wrapped by msb at sq.com on Tue Feb 19 22:10:54 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'zgrep' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'zgrep'\"
else
echo shar: Extracting \"'zgrep'\" \(541 characters\)
sed "s/^X//" <<'END_OF_FILE' | tr '&' '\030' >zgrep
X#!/bin/sh
X: zg - "zcat | grep (or egrep or fgrep)"
X
grep=`basename $0 | sed 's/z//'`
X
dashl=""
opts=""
for arg
do
X	case "x$arg" in
X	x-l)		dashl=y; shift;;
X	x-[a-zA-Z])	opts="$opts $arg"; shift;;
X	*)		pat="$arg"; shift; break;;
X	esac
done
X
case "x$dashl" in
xy)	for file
X	do
X		if zcat <"$file" | $grep $opts "$pat" >/dev/null
X		then
X			echo "$file"
X		fi
X	done
X	exit
esac
X
case $# in
X0)	zcat | $grep $opts "$pat"; exit;;
X1)	zcat <"$1" | $grep $opts "$pat"; exit;;
esac
X
for file
do
X	zcat <"$file" | $grep $opts "$pat" | sed "s&^&$file:&"
done
END_OF_FILE
if test 541 -ne `wc -c <'zgrep'`; then
    echo shar: \"'zgrep'\" unpacked with wrong size!
fi
chmod +x 'zgrep'
# end of 'zgrep'
fi
echo shar: End of shell archive.
exit 0
-- 
Mark Brader		    "Howeb45 9 qad no5 und8ly diturvrd v7 7jis dince
SoftQuad Inc., Toronto	     9 qas 8mtillihemt mot ikkfavpur4d 5esoyrdeful
utzoo!sq!msb, msb at sq.com     abd fill if condif3nce on myd3lf."      -- Cica

This article is in the public domain.



More information about the Comp.unix.shell mailing list