- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Grep Recursively and find a pattern in gzipped fil...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-14-2006 06:28 AM
тАО12-14-2006 06:28 AM
Grep Recursively and find a pattern in gzipped files on Linux
e.g
grep
grep
please advise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-14-2006 06:48 AM
тАО12-14-2006 06:48 AM
Re: Grep Recursively and find a pattern in gzipped files on Linux
This should work.
# find /path -xdev -type f -name "*.gz" | xargs -n1 -t gzip -d -c | grep pattern
For example, given '/tmp/hosts.gz' and '/tmp/services.gz' --- copies of the standard files, gzipped:
# find /tmp -xdev -type f -name "*.gz" | xargs -n1 -t gzip -d -c |grep local
...produces:
gzip -d -c /tmp/hosts.gz
127.0.0.1 localhost loopback
gzip -d -c /tmp/services.gz
hacl-local 5304/tcp # HA Cluster Commands
...by using the trace option of 'xargs' and processing one argument at a time ('-n 1') we can show the filename in which the match occurs. Your files are only uncompressed on-the-fly. They are left unchanged on disk.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-14-2006 07:12 AM
тАО12-14-2006 07:12 AM
Re: Grep Recursively and find a pattern in gzipped files on Linux
My original post was done on HP-UX. On a Linux server, substitute '-L1' for '-n1' in the options to 'xargs'.
Thus, for Linux:
# find /tmp -xdev -type f -name "*.gz" | xargs -L1 -t gzip -d -c |grep local
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 02:00 PM
тАО12-29-2006 02:00 PM
Re: Grep Recursively and find a pattern in gzipped files on Linux
On linux you could do
# find /tmp -xdev -type f -name "*.gz" | xargs -n1 zgrep local
that is use zgrep ... this is a grep on a gzip file.
man zgrep
for more on this command.
Jean-pierre Huc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2006 02:35 PM
тАО12-30-2006 02:35 PM
Re: Grep Recursively and find a pattern in gzipped files on Linux
find /tmp -xdev -type f -name "*.gz" -exec zgrep -H local {} \;
The '-H' will print the filename of the match, along with the matched line. if you just want the filename, use '-l' in the grep.