Newsgroups: comp.unix.shell Path: utzoo!sq!msb From: msb@sq.sq.com (Mark Brader) Subject: Re: does a zgrep exist? (zgrep <> zcat | grep) Message-ID: <1991Feb20.032144.21501@sq.sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <1991Feb15.182057.18875@convex.com> Date: Wed, 20 Feb 91 03:21:44 GMT Lines: 72 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 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@sq.com abd fill if condif3nce on myd3lf." -- Cica This article is in the public domain.