gzcat/grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gzcat/grep
# 1  
Old 06-24-2009
gzcat/grep

Hi!!!

I am trying to grep a number in more then 1000 files which are .gz.
Below is the code :-


Code:
for i in `ls 20090618yz*_07.znf.gz`
do
a=`gzcat 20090618yz*_07.znf.gz | grep 9814843011`
if [ -n "$a" ]
then
echo $i 
fi
done

My objective is to echo the file name also with the data.

Please help!!!!
Thanks in advance....

Last edited by vidyadhar85; 06-24-2009 at 11:24 AM.. Reason: CODE TAGS ADDED
# 2  
Old 06-24-2009
Please use code tags! do you have zgrep? or gzgrep?
Code:
for i  in 20090618yz*_07.znf.gz
do
  [[  zgrep -q 9814843011 $i ]] && echo "$i"
done

This works with my zgrep. It will also run a lot faster without all of the `` and extra processes your were creating.
# 3  
Old 06-24-2009
Do you have awk:

Code:
gzcat filename | nawk '/pattern/ {printf "%s %s\n",$0,FILENAME}'

# 4  
Old 06-24-2009
No the awk didn`t worked.
It gave me the same output as before, no filename in it.
Below is the output string without filename.

# # #20090618# # # # # # # # # #9#919814843011# #91# # # #3496#-100# # # # # # # #D@27#1# -



Also i dont have zgrep installed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. Shell Programming and Scripting

gzcat number of records

Hey guys, I want to do something quite simple but I just can't no matter what I try. I have a large file and i usually just: gzcat test.gz | nohup /test/this-script-does-things-to-the-records.pl -> /testdir/tmp_test.txt But now I need to do it only for the first 100k records. I sure... (7 Replies)
Discussion started by: sg3
7 Replies

3. UNIX for Dummies Questions & Answers

gzcat help

Hi, I am using under-noted script and getting the error as under. Please help. Executing each individual cat / gzcat gives correct answer. gzcat /logs/1205* gzcat /logs/12052* cat /logs/12052 | egrep -v "XYZ|PQR"|wc -l gzcat: gzcat.gz: No such file or directory gzcat: cat.gz: No such... (2 Replies)
Discussion started by: vanand420
2 Replies

4. Shell Programming and Scripting

[Solved] Read a .gz file line by line without using gzcat

Hi all Is there a way to read and process a gzip file line by line similar to a text file without using gzcat.. while processing a text file we will usually use the logic exec<sample.txt while read line do echo $line done Is there a similar way to process the gz file in the same... (4 Replies)
Discussion started by: aikhaman
4 Replies

5. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

6. UNIX for Dummies Questions & Answers

How to list file names instead of lines when grep a gzcat command?

Hi, I want to list filenames instead of lines when i search in compresed files for a string. #gzcat *.gz | grep -l 12345 gives me: <stdin> Anyone got a solution on this problem? (2 Replies)
Discussion started by: HugoH
2 Replies

7. Shell Programming and Scripting

performance issue using gzcat, awk and sort

hi all, I was able to do a script to gather a few files and sort them. here it is: #!/usr/bin/ksh ls *mainFile* |cut -c20-21 | sort > temp set -A line_array i=0 file_name='temp' while read file_line do line_array=${file_line} let i=${i}+1 (5 Replies)
Discussion started by: naoseionome
5 Replies

8. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

9. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

10. UNIX for Dummies Questions & Answers

gzcat (or gunzip -c)

Does anyone know what kind of impact gunzip -c or gzcat has on a system? I am using gunzip -c on files that around 30 Mb compressed and 300Mb uncompressed. How much memory or disk space gets used? Also does anyone know how gunzip -c actually works? The system I am running on is AIX Version 5. ... (1 Reply)
Discussion started by: windjunky
1 Replies
Login or Register to Ask a Question