<p>I have over a million text files compressed into 40 zip files. I also have a list of about 500 model names of phones. I want to find out the number of times a particular model was mentioned in the text files. </p>

<p>Is there any python module which can do a regex match on the files without unzipping it. Is there a simple way to solve this problem without unzipping?</p>

[{'answer_id': 14304, 'author': 'jdd', 'author_id': 242853, 'author_profile': 'https://Stackoverflow.com/users/242853', 'pm_score': 0, 'selected': False, 'text': "<p>You could loop through the zip files, reading individual files using the zipfile module and running your regex on those, eliminating to unzip all the files at once. </p>\n\n<p>I'm fairly certain that you can't run a regex over the zipped data, at least not meaningfully.</p>\n"}, {'answer_id': 14314, 'author': 'Craig.Nicol', 'author_id': 1404, 'author_profile': 'https://Stackoverflow.com/users/1404', 'pm_score': 0, 'selected': False, 'text': '<p>To access the contents of a zip file you have to unzip it, although the zipfile package makes this fairly easy, as you can unzip each file within an archive individually.</p>\n\n<p><a href="http://docs.python.org/lib/module-zipfile.html" rel="nofollow noreferrer">Python zipfile module</a></p>\n'}, {'answer_id': 14320, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 4, 'selected': True, 'text': "<p>There's nothing that will automatically do what you want.</p>\n\n<p>However, there is a python zipfile module that will make this easy to do.  Here's how to iterate over the lines in the file.</p>\n\n<pre><code>#!/usr/bin/python\n\nimport zipfile\nf = zipfile.ZipFile('myfile.zip')\n\nfor subfile in f.namelist():\n    print subfile\n    data = f.read(subfile)\n    for line in data.split('\\n'):\n        print line\n</code></pre>\n"}, {'answer_id': 41822, 'author': 'Chris Conway', 'author_id': 1412, 'author_profile': 'https://Stackoverflow.com/users/1412', 'pm_score': 0, 'selected': False, 'text': "<p>Isn't it (at least theoretically) possible, to read in the ZIP's Huffman coding and then translate the regexp into the Huffman code? Might this be more efficient than first de-compressing the data, then running the regexp?</p>\n\n<p>(Note: I know it wouldn't be quite that simple: you'd also have to deal with other aspects of the ZIP coding&mdash;file layout, block structures, back-references&mdash;but one imagines this could be fairly lightweight.)</p>\n\n<p>EDIT: Also note that it's probably much more sensible to just use the <code>zipfile</code> solution.</p>\n"}]
['https://Stackoverflow.com/questions/14281', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1448/']