Visit Our UNIX and Linux User Community


How to perform Grep on many Gzip files, Searching for Specific information


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to perform Grep on many Gzip files, Searching for Specific information
# 1  
Old 07-27-2009
How to perform Grep on many Gzip files, Searching for Specific information

Hello,

I am wondering if you can assist with my question and ask kindly for this.

I have a number of files that are listed as file1.gz through file100.gz.

I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are multiple entries within the file so I am try to also limit the amount of output with the tail or head command.


My command is something like this, although it is incorrect:

gunzip -c file1.*.gz |grep -v "Jul 25 22:16:09" | tail -n 20


Thank you kindly.
# 2  
Old 07-27-2009
You want the name of the file that has Jul 25 22:16:09 in it correct?

Code:
for filename in file*.gz
do
    gunzip $filename | grep -q 'Jul 25 22:16:09'
    if [[ $? -eq 0 ]] ; then
        echo $filename
        break
    fi
done

# 3  
Old 07-27-2009
You might look at zgrep to simplify your answer (assuming it's available on your platform)

Code:
zgrep "Jul 25 22:16:09" file1.*.gz | tail -n 20

More info:

The Power of Z Commands - Zcat, Zless, Zgrep, Zdiff Examples (link removed)
zgrep(1) - Linux man page
# 4  
Old 07-27-2009
Thanks much to those that responded.

Will try what was suggested and advise.

Best regards.

Previous Thread | Next Thread
Test Your Knowledge in Computers #309
Difficulty: Easy
FLAC stands for 'Free Lossless Audio Condenser';
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching the value of a specific attribute among xmls files from a particular directory location

Hi Folks , I have the different xml files at the following directory `/opt/app/rty/servers/tr/current/ops/config` Let's say there are three files named abc.xml bv.xml ert.xml Now inside these xml there can be many tags as like shown below <bean id="sdrt"... (6 Replies)
Discussion started by: unclesamm
6 Replies

2. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

3. UNIX for Dummies Questions & Answers

Grep in Perl - Searching through multiple files

I'm attempting to use grep in Perl with very little success. What I would like to do in Perl is get the output of the following grep code: grep -l 'pattern' * This gives me a list of all the files in a directory that contain the pattern that was searched. My attempts to do this in Perl... (4 Replies)
Discussion started by: WongSifu
4 Replies

4. UNIX for Dummies Questions & Answers

Grep bunch of gzip files to count based on category

Started using unix commands recently. I have 50 gzip files. I want to grep each of these files for a line count based particular category in column 3. How can I do that? For example Sr.No Date City Description Code Address 1 06/09 NY living here 0909 10st st nyc 2 ... (5 Replies)
Discussion started by: jinxx
5 Replies

5. Shell Programming and Scripting

Searching for files with specific extensions

Hi, Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log. I've tried to use ls *.txt *.log which works if there are both... (4 Replies)
Discussion started by: neilmw
4 Replies

6. Shell Programming and Scripting

perform some operation on a specific coulmn starting from a specific line

I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. eg: 50.000000 1 1 1 1000.00000 1000.00000 50000.000 19 19 3.69797533E-07 871.66394 ... (3 Replies)
Discussion started by: shashi792
3 Replies

7. Shell Programming and Scripting

Need help in searching 2 files for strings then perform an action

I have 2 files. I basically want to search both of them to see if the 1st column ($1) matches and if it matches then check to see if the 2nd column ($2) matches, then execute some code showing the results of the matches. File 1: AAA 123 misc blah BBB 456 CCC 789 File 2: ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

8. Shell Programming and Scripting

grep - searching for a specific string

ppl, this is my "file" with fields orderno orderdate orderdesc telno street city 1 01/04/2006 abc 123 100 tampa 2 01/04/2006 abc 123 100 tampa 3 01/04/2006 abc 123 100 tampa 4 01/04/2006 abc ... (2 Replies)
Discussion started by: manthasirisha
2 Replies

9. UNIX for Dummies Questions & Answers

searching text files on specific columns for duplicates

Is it possible to search through a large file full of rows and columns of text and retrieve only the rows that contain duplicates fields, searchiing for duplicates on col4 & col6 Sample below Col1 col2 col3 col4 col5 col6 G405H SURG FERGUSON ... (2 Replies)
Discussion started by: Gerry405
2 Replies

Featured Tech Videos