Grep a pattern from zip file which has multiple files insdie

Tags
advanced, file, grep, multiple files, zip

 
Thread Tools Search this Thread
# 1  
Old 09-13-2018
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 05:08 PM.. Reason: Please use real CODE tags, not {code}!
# 2  
Old 09-17-2018
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.

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

More UNIX and Linux Forum Topics You Might Find Helpful
Grep date pattern folder and zip -->delete onenessboy Shell Programming and Scripting 1 10-16-2018 10:11 AM
How can we Zip multiple files created on the same date into one single zip file.? b.saipriyanka Shell Programming and Scripting 1 01-30-2017 01:47 PM
How can we Zip multiple files created on the same date into one single zip file.? b.saipriyanka UNIX for Beginners Questions & Answers 2 01-30-2017 10:37 AM
Concatenation of multiple files based on file pattern Jesshelle David UNIX for Advanced & Expert Users 1 08-22-2016 07:00 PM
Wanted to replace string in an .xlsx file in multiple ZIP Files vipinmaster UNIX for Advanced & Expert Users 1 09-03-2014 05:34 PM
Create multiple zip files each containing 50 xml files. Rakesh Thobula Shell Programming and Scripting 6 01-16-2014 09:12 PM
Zip Multiple files to One .zip file in AIX system RAMA PULI Shell Programming and Scripting 9 04-29-2013 01:11 PM
Help to search multiple pattern in file with grep/sed/awk gr8_usk Shell Programming and Scripting 9 07-21-2011 12:31 PM
how to find files matching a pattern and zip james423 Shell Programming and Scripting 4 11-27-2010 03:20 AM
How to grep multiple pattern from XML file revertback Shell Programming and Scripting 6 04-07-2010 12:23 PM
grep for a record within *zip files sureshg_sampat Shell Programming and Scripting 4 03-19-2010 02:15 PM
ZIP multiple files and also specify size of zip file tom007 AIX 1 03-16-2010 03:29 AM
Grep for a particular ID in zip files jyothi_wipro Solaris 1 01-25-2010 04:55 AM
unzip .zip file and list the files included in the .zip archive oracledev UNIX for Dummies Questions & Answers 5 04-08-2008 05:49 PM