how to grep word from .gz files & .z files

Hi I have find some account numbers from .gz files.

There thousands of .gz files, also i am unable to grep .gz / .z files.

I want to find file names & and those lines from list.

Could you pls tell me / give me any syntax for finding word from ,gz files using grep?

Thanks in advance

zgrep test *

nuh8923:MERP:/apps/mercury/data/MERP_ARCHIVE/OUTBOUND/done> zgrep 20060324179536081 TBS20060325M25MB-6
ksh: zgrep: not found

am getting this error.

try
man zgrep

reason being I could do that & mine is /bin/sh

Heres the zgrep on my machine.

Just save this piece of code in your /usr/local/bin/zgrep and change the permission chmod +x /usr/local/bin/zgrep and use it

more /usr/local/bin/zgrep
#!/bin/sh

# zgrep -- a wrapper around a grep program that decompresses files as needed
# Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>

PATH="/usr/local/bin:$PATH"; export PATH

prog=`echo $0 | sed 's|.*/||'`
case "$prog" in
*egrep) grep=${EGREP-egrep} ;;
*fgrep) grep=${FGREP-fgrep} ;;
) grep=${GREP-grep} ;;
esac
pat=""
while test $# -ne 0; do
case "$1" in
-e | -f) opt="$opt $1"; shift; pat="$1"
if test "$grep" = grep; then # grep is buggy with -e on SVR4
grep=egrep
fi;;
-
) opt="$opt $1";;
*) if test -z "$pat"; then
pat="$1"
else
break;
fi;;
esac
shift
done

if test -z "$pat"; then
echo "grep through gzip files"
echo "usage: $prog [grep_options] pattern [files]"
exit 1
fi

list=0
silent=0
op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
case "$op" in
*l*) list=1
esac
case "$op" in
*h*) silent=1
esac

if test $# -eq 0; then
gzip -cdfq | $grep $opt "$pat"
exit $?
fi

res=0
for i do
if test $list -eq 1; then
gzip -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
r=$?
elif test $# -eq 1 -o $silent -eq 1; then
gzip -cdfq "$i" | $grep $opt "$pat"
r=$?
else
gzip -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
r=$?
fi
test "$r" -ne 0 && res="$r"
done
exit $res
netx@ndcnxg30% more zgrep
zgrep: No such file or directory
netx@ndcnxg30% more /usr/local/bin/zgrep
#!/bin/sh

# zgrep -- a wrapper around a grep program that decompresses files as needed
# Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>

PATH="/usr/local/bin:$PATH"; export PATH

prog=`echo $0 | sed 's|.*/||'`
case "$prog" in
*egrep) grep=${EGREP-egrep} ;;
*fgrep) grep=${FGREP-fgrep} ;;
) grep=${GREP-grep} ;;
esac
pat=""
while test $# -ne 0; do
case "$1" in
-e | -f) opt="$opt $1"; shift; pat="$1"
if test "$grep" = grep; then # grep is buggy with -e on SVR4
grep=egrep
fi;;
-
) opt="$opt $1";;
*) if test -z "$pat"; then
pat="$1"
else
break;
fi;;
esac
shift
done

if test -z "$pat"; then
echo "grep through gzip files"
echo "usage: $prog [grep_options] pattern [files]"
exit 1
fi

list=0
silent=0
op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
case "$op" in
*l*) list=1
esac
case "$op" in
*h*) silent=1
esac

if test $# -eq 0; then
gzip -cdfq | $grep $opt "$pat"
exit $?
fi

res=0
for i do
if test $list -eq 1; then
gzip -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
r=$?
elif test $# -eq 1 -o $silent -eq 1; then
gzip -cdfq "$i" | $grep $opt "$pat"
r=$?
else
gzip -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
r=$?
fi
test "$r" -ne 0 && res="$r"
done
exit $res

If you lack zgrep you can do this:

zcat | grep STRING

don't forget about gzgrep. I use it all the time.

USE 'gzgrep' utility

The several times mentioned z* commands are often only available on Linux.
Anyway on most other Unices you should be able to resort to

$ gzip -dc zippedfile.gz | grep somepattern