gzcat/grep


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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 12:24 PM.. Reason: CODE TAGS ADDED
# 2  
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  
Do you have awk:

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

# 4  
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #793
Difficulty: Easy
The base-2 numeral system is a positional notation with a radix of 3.
True or False?

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. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

5. 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

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

Featured Tech Videos