LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-16-2018, 01:57 AM   #1
sakusri16
LQ Newbie
 
Registered: Aug 2017
Posts: 13

Rep: Reputation: Disabled
Find a string from gz files


Hi Guru

I have tried to find a particular string lines from gz files , when we use the below command its not displaying fully . I can see 25% of the log files details only . Please give suggestion to store a output of the grep in a separate file .

find -name \*.access.log.30.gz -print0 | xargs -0 zgrep "googlebot"


Thanks
Srini
 
Old 03-16-2018, 09:54 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
I'm not specifically familiar with a command called zgrep but I do know that the gunzip command can be used in-line in that situation, something like ...

find . -name \*.access.log.30.gz -print0 | gunzip | grep "googlebot"

(In this construction, "gunzip" takes the compressed stream – produced by "-print0" – as its STDIN and emits the uncompressed stream as its STDOUT which is then piped to "grep" or "egrep.")

(And Windows/DOS programmers think they have all the fun!)

Last edited by sundialsvcs; 03-16-2018 at 09:55 AM.
 
Old 03-16-2018, 10:21 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,343

Rep: Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989
Quote:
Originally Posted by sakusri16 View Post
Hi Guru

I have tried to find a particular string lines from gz files , when we use the below command its not displaying fully . I can see 25% of the log files details only . Please give suggestion to store a output of the grep in a separate file .

find -name \*.access.log.30.gz -print0 | xargs -0 zgrep "googlebot"
Perhaps those are not single-line log entries. You'll see only the line that contains the word you asked for. If that's the case, you can use the "-A nn" (--after-context=nn) and/or "-B nn" (--before-context=nn) to see the surrounding lines.

Storing the output in a file is simple. Just direct the final output there:
Code:
find -name \*.access.log.30.gz -print0 | xargs -0 zgrep "googlebot" >some_file
If you want to see the output as it's being produced and stored, use the tee utility:
Code:
find -name \*.access.log.30.gz -print0 | xargs -0 zgrep --line-buffered "googlebot" | tee some_file
Note the use of "--line-buffered" there. With its output going to a pipe, zgrep would default to block-buffered and send 4KB blocks instead of individual lines.
 
Old 03-17-2018, 04:46 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,229
Blog Entries: 9

Rep: Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618Reputation: 3618
i'd get rid of the find, it's not really necessary here.
there's also zcat, might be easier to troubleshoot:
Code:
zcat *.access.log.30.gz | grep "googlebot"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a String in Multiple Files raihan26 Linux - Newbie 3 07-28-2012 04:04 AM
[SOLVED] How to find files that contain one string, but don't contain another. PatrickDickey Linux - Newbie 2 09-11-2011 07:00 AM
[SOLVED] How to find a string in files under the current directory? thomas2004ch Linux - Newbie 4 10-05-2010 07:41 AM
find a string in all ASCII files of a system markraem Linux - Software 5 12-12-2007 05:08 AM
How to find those files having specific string??? saeed Red Hat 4 07-19-2006 12:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration