How to search for a string within a zip


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to search for a string within a zip
# 1  
Old 12-15-2009
How to search for a string within a zip

Hi Guys,

We have some really large zip files containing hundreds of files, we need to search within these compressed files for a string in the filename eg ABC if found then extract the file from the zip ?

I've searched for a long time but no joy

Any help really appreciated

Thanks

Pete
# 2  
Old 12-15-2009
Hi, have you checked out zipinfo and zipgrep?
# 3  
Old 12-15-2009
Hi

Yeah I have checked them out but can't see a way to search lots of zip files within a directory and only extract if a match is found on part of the filename within the zip.

Cheers

Pete
# 4  
Old 12-15-2009
OK, how about:
Code:
unzip "*.zip" "*ABC*"

This should extract every file whose name contains "ABC" from every zip archive in the current directory
# 5  
Old 12-15-2009
Won't this have to extract the data in order to find the files ? The problem is the machine is our main database server and I cannot risk uncompressing loads of files and filling up the disk. I have tried the following find command

find . -name '*.zip' -exec grep -qi '*ABC*' {} \; -exec echo {} \;

This finds and lists the files but how do I then tell unzip to only the unzip files it found the file in and not to unzip everthing just to extract files containing ABC in the filename.

Cheers

Pete
# 6  
Old 12-15-2009
The command I posted should only extract the files that match the pattern. I just did a test to verify and I think that is what happened.

Code:
$ unzip "*.zip" "*g*"
Archive:  testzipper.zip
replace dfgdhdgfdreggegerg? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
 extracting: dfgdhdgfdreggegerg

Archive:  testz2.zip
 extracting: dfgdhdgfdreggegerg

2 archives were successfully processed.

But it is never a good idea to test something on a production server. Why don't you copy one or two of those zip files onto a test server and test it yourself so you can be sure.
# 7  
Old 12-15-2009
Yes I have copied some of the files to a test machine and confirmed that I did only need to do unzip "*.zip" "*ABC*" which worked great

Thanks for your help Smilie

cheers

Pete
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Beginners Questions & Answers

Tar.gz/zip folders in a directory with _EBASE string

Hi Folks - Happy Friday and I hope you all are well! What's the easiest way to tar.gz / zip all direct children directories in a folder that have the string _EBASE (suffix)? Thank you! (6 Replies)
Discussion started by: SIMMS7400
6 Replies

3. UNIX for Advanced & Expert Users

Wanted to replace string in an .xlsx file in multiple ZIP Files

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... (1 Reply)
Discussion started by: vipinmaster
1 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Search one string and then search another string in the next line

I am unable to use grep comman to Print only EmpPosition and if the EmpID next line. So output should be both EmpPosition and EmpID and also EmpPosition and EmpID data should match. Sample Data EmpPosition "New" EmpID "New" - - EmpPosition "New" ... (4 Replies)
Discussion started by: onesuri
4 Replies

6. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

7. UNIX for Dummies Questions & Answers

search for a string in zip file

Hi, I know gzcat helps grep for a string inside a file that has been zipped using gzip command. However, how can the same be achieved for files zipped using zip command and any other compression commands you may know off. Thanks, Mohtashim (5 Replies)
Discussion started by: mohtashims
5 Replies

8. UNIX for Dummies Questions & Answers

Search through 2 levels of zip

Hi guys, I know I'm missing something simple here. We have about 500 zipped files in a directory which contain more zip files and within those I need to find a file without unzipping everything. I know I can use zipinfo which I'm trying to create a for loop to go through the files and... (4 Replies)
Discussion started by: petef
4 Replies

9. Shell Programming and Scripting

Matching a string (zip code) from a list in a separate file

I have a list of postal addresses and I need to pull the records that match a list of zip codes in a separate file. The postal addresses are fixed width. The zip code is located in character position 149-157. Something better than: cat postalfile.txt | grep -f zipcodes.txt would be great. $... (8 Replies)
Discussion started by: sitney
8 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question