The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extract same word from two files tjmannonline AIX 4 04-06-2008 12:42 PM
How to replace one word across too many files at once moe2266 Shell Programming and Scripting 2 12-15-2006 10:56 AM
searching word in files naamas03 UNIX for Dummies Questions & Answers 2 11-06-2006 05:26 AM
search for certain word in a files from directory legato UNIX for Dummies Questions & Answers 1 10-31-2006 06:35 AM
word count ascii files madtim UNIX for Dummies Questions & Answers 1 08-27-2002 01:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
udaya_subbu udaya_subbu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
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
  #2 (permalink)  
Old 02-19-2008
Krishnaramjis Krishnaramjis is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
zgrep test *
  #3 (permalink)  
Old 02-19-2008
udaya_subbu udaya_subbu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
It's not working

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


am getting this error.
  #4 (permalink)  
Old 02-19-2008
Krishnaramjis Krishnaramjis is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
try
man zgrep

reason being I could do that & mine is /bin/sh
  #5 (permalink)  
Old 02-19-2008
knijjar knijjar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 27
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
  #6 (permalink)  
Old 02-19-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
If you lack zgrep you can do this:

zcat | grep STRING
  #7 (permalink)  
Old 02-20-2008
timj123 timj123 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 80
don't forget about gzgrep. I use it all the time.
Closed Thread

Bookmarks

Tags
linux commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0