Grep a pattern from zip file which has multiple files insdie


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Grep a pattern from zip file which has multiple files insdie

Hi Gurus,


I got a small requirement in my script to grep a specific pattern in a zip compressed file which has been created with multiple files.


Sample File: 20180913.zip


Code:
$> zipinfo -l 20180913.zip
20180913_file1
20180913_file2
20180913_file3
20180912_file4
20180912_file5
20180911_file6
20180911_file7
$>

I need to grep a country Mexico in all these files in the zip and print the content. Can someone provide any relevant article or exact way to accomplish it please?


Thanks in Advance.
Venkat

Last edited by Scott; 09-13-2018 at 04:08 PM.. Reason: Please use real CODE tags, not {code}!
# 2  
If the archive isn't compressed, just using:
Code:
grep Mexico archive

might give you the lines you want in all of the files in the archive.

If the archive is compressed or if you need to know which files in the archive contain matching lines, the typical way to do so it to create a new directory, unzip the files in the archive into that directory, move into that directory, and then run:
Code:
grep Mexico *

Some versions of zip/unzip may have options to do what you want without unziping the archive. Since you haven't given us any indication of what operating system you're using, we can't make any guess at whether or not your implementation might have such an option.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How can we Zip multiple files created on the same date into one single zip file.?
b.saipriyanka
Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping...... Shell Programming and Scripting
1
Shell Programming and Scripting
How can we Zip multiple files created on the same date into one single zip file.?
b.saipriyanka
Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping...... UNIX for Beginners Questions & Answers
2
UNIX for Beginners Questions & Answers
Wanted to replace string in an .xlsx file in multiple ZIP Files
vipinmaster
Hi , I am having a ZIP file containing an .xlsx file . Now i wanted to replace "GJ" to blank in the .xlsx file . I tried using the below code but not working , Please guide : #!/bin/bash log="/home/srikant/scripts/replacescriptFHO.log" date > $log echo "" >> $log echo initiating for FHO...... UNIX for Advanced & Expert Users
1
UNIX for Advanced & Expert Users
Zip Multiple files to One .zip file in AIX system
RAMA PULI
Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want...... Shell Programming and Scripting
9
Shell Programming and Scripting
ZIP multiple files and also specify size of zip file
tom007
I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a...... AIX
1
AIX
UNIX and Linux

Unix (trademarked as the UNIX certification mark) is a very mature family of multitasking, multiuser computer operating systems that evolved from the original AT&T Unix. Unix development starting in the 1970s by legendary Bell Labs programmers Ken Thompson, Dennis Ritchie, and others. Unix was first targeted for the Bell System and AT&T licensed Unix to outside parties. In the 1970s time period, this lead to a variety of for-profit as well as not-for-profit Unix variants.
In the early days, this included the University of California, Berkeley (BSD), Microsoft (Xenix), IBM (AIX), and Sun Microsystems (Solaris). In the early 1990s, AT&T sold their Unix rights to Novell. In 1995 Novell sold their Unix business to the Santa Cruz Operation (SCO). The UNIX trademark was passed to The Open Group, a "neutral" industry consortium. The Open Group promoted the use of the UNIX trademark for certified operating systems that comply with the Single UNIX Specification (SUS). In 2014 Apple's macOS became the Unix version with the largest global install base and macOS remains the largest Unix-user base today.
Linux is a family of open source Unix-like operating systems based on the Linux kernel. The Linux kernel is an operating system kernel first released by Linus Torvalds on 17 September 1991. Linux distributions include the Linux kernel, system software and libraries. Popular free open source Linux distributions include Debian, Fedora, and Ubuntu. Commercial Linux distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Linux may be freely modified and redistributed. Anyone on the planet may create a Linux distribution for any purpose.
Please enjoy and help our forum community by "showing your work" and posting your code, even when your code is not working as expected. To help others help you, please wrap your code blocks, sample input, sample output, error messages, and other data in CODE tags and wrap your short commands and short data objects in ICODE tags. We were all beginners in the beginning. If you have any questions about how to register or how to post, please contact us in Live Chat. Thank you and enjoy this "forever free" technical support community for UNIX, Linux and computer information technology in general.