From owner-cvs-all Fri Sep 13 3:29:37 2002 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E62CE37B400; Fri, 13 Sep 2002 03:29:23 -0700 (PDT) Received: from mta7.pltn13.pbi.net (mta7.pltn13.pbi.net [64.164.98.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7698343E77; Fri, 13 Sep 2002 03:29:23 -0700 (PDT) (envelope-from makonnen@pacbell.net) Received: from kokeb.ambesa.net ([64.173.11.119]) by mta7.pltn13.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0H2D005C7H4YYL@mta7.pltn13.pbi.net>; Fri, 13 Sep 2002 03:29:23 -0700 (PDT) Received: from kokeb.ambesa.net (tanstaafl@localhost [IPv6:::1]) by kokeb.ambesa.net (8.12.6/8.12.6) with ESMTP id g8DATLQn020593; Fri, 13 Sep 2002 03:29:21 -0700 (PDT envelope-from mtm@kokeb.ambesa.net) Received: (from mtm@localhost) by kokeb.ambesa.net (8.12.6/8.12.6/Submit) id g8DATK2o020592; Fri, 13 Sep 2002 03:29:20 -0700 (PDT) Date: Fri, 13 Sep 2002 03:29:20 -0700 From: Mike Makonnen Subject: Re: cvs commit: src/etc newsyslog.conf In-reply-to: <86ofb3c75p.wl@archon.local.idaemons.org> To: Akinori MUSHA Cc: kris@obsecurity.org, sobomax@FreeBSD.ORG, obrien@FreeBSD.ORG, cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG Message-id: <20020913032920.0cbd1a4b.mtm@identd.net> MIME-version: 1.0 X-Mailer: Sylpheed version 0.8.2 (GTK+ 1.2.10; i386-portbld-freebsd5.0) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT References: <200209121728.g8CHS7An013425@freefall.freebsd.org> <3D80D22F.B7BDF10E@FreeBSD.org> <20020912193532.GA21745@xor.obsecurity.org> <86ofb3c75p.wl@archon.local.idaemons.org> Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, 13 Sep 2002 04:57:54 +0900 "Akinori MUSHA" wrote: > > I'd note that our zgrep(1) does not support bz2 files nor have we > something called bzgrep(1). It is a mess that you can't do a grep > over uncompressed files, gzip'd files and bzip2'd files at once. > > Do we have as handy a command as the following one that used to work > before the switchover? > > $ zgrep foo messages* Well, The current zgrep(1) is really grep(1); however, there is a zgrep in src/gnu/usr.bin/gzip, which with th following patch will support bziped files. Just install _that_ script instead of hardlinking zgrep to grep at install time, and then hardlink bzgrep to zgrep. $ zgrep foo messages * will do what you want irrespective of compression type (gzip or bzip2). But whether you use zgrep or bzgrep will determine how files with unknown suffixes will be decompressed. Cheers, Mike Makonnen. Index: gnu/usr.bin/gzip/zgrep =================================================================== RCS file: /home/ncvs/src/gnu/usr.bin/gzip/zgrep,v retrieving revision 1.3 diff -u -r1.3 zgrep --- gnu/usr.bin/gzip/zgrep 27 Aug 1999 23:35:55 -0000 1.3 +++ gnu/usr.bin/gzip/zgrep 13 Sep 2002 10:14:09 -0000 @@ -5,8 +5,45 @@ # # $FreeBSD: src/gnu/usr.bin/gzip/zgrep,v 1.3 1999/08/27 23:35:55 peter Exp $ +GZIP="/usr/bin/gzip" +BZIP2="/usr/bin/bzip2" +zipcmd="$GZIP" +zipflags="-cdfq" # gzip and bzip2 use (mostly) the same flags +defaultzip="gzip" + +# cmd_from_suffix file +# Takes one optional argument (file). Sets the global zipcmd and +# zipflag variables according to the type of compressed file. If +# a file is not specified, it uses the default compression type. +# +cmd_from_suffix() +{ + _match=1 + if test $# -ne 0 ; then + if test "`expr "$1" : '.*\.\(gz\)$'`" = "gz" ; then + zipcmd="$GZIP" + elif test "`expr "$1" : '.*\.\(bz2\)$'`" = "bz2" ; then + zipcmd="$BZIP2" + else + _match=0 + fi + fi + if test $# -eq 0 -o $_match -eq 0 ; then + if test "$defaultzip" = "bzip2" ; then + zipcmd="$BZIP2" + else + zipcmd="$GZIP" + fi + fi + zipcmd="$zipcmd $zipflags" +} + prog=`echo $0 | sed 's|.*/||'` case "$prog" in + bz*) defaultzip="bzip2" ;; + z*) defaultzip="gzip" ;; +esac +case "$prog" in *egrep) grep=${EGREP-egrep} ;; *fgrep) grep=${FGREP-fgrep} ;; *) grep=${GREP-grep} ;; @@ -49,22 +86,25 @@ *h*) silent=1 esac +zipcmd="$zipcmd $zipflags" if test $fileno -eq 0; then - gzip -cdfq | $grep $opt "$pat" + cmd_from_suffix + $zipcmd | $grep $opt "$pat" exit $? fi eval set "$A" # files in $1, $2 ... res=0 for i do + cmd_from_suffix $i if test $list -eq 1; then - gzip -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i + $zipcmd "$i" | $grep $opt "$pat" > /dev/null && echo $i r=$? elif test $# -eq 1 -o $silent -eq 1; then - gzip -cdfq "$i" | $grep $opt "$pat" + $zipcmd "$i" | $grep $opt "$pat" r=$? else - gzip -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|" + $zipcmd "$i" | $grep $opt "$pat" | sed "s|^(standard input):|${i}:|" r=$? fi test "$r" -ne 0 && res="$r" To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message