I am looking for a way to search the content of files inside of a 7-Zip archive (.7z) without having to unpack the archive. I have many 7-Zip archives with code inside them and I'd like to search them.
Is there a way to do that?
On Windows, use a command prompt:
cd C:\Program Files\7-Zip
To search for a specific file, e.g.
7z l compressed.tar namefile -r
Video tutorial: Search files with 7-Zip
dnGrep is an excellent Windows grep implementation that has an archive file plugin that works with all archive formats. You can use Regex, Xpath, Text, or phonetic for your search.
Try out SearchInZipFiles: It is a simple Open Source Tool for Windows located on Sourceforge:
On Windows, there exist a few utilities that can search the contents of files inside compressed archives with no decompression. Below are a couple of such products:
Free and open-source, it can search zip, 7z, rar, jar, and many more archive formats. It also displays a preview of the found text in the files contained inside the archive. I tested it and it works as claimed.
FileLocator Pro and Agent Ransack (commercial)
Both products advertise their capability for searching compressed archives, but I have not tested it.
As others have said, no there is no way. To examine the contents of a file, it needs to be unpacked (regardless of if the files are compressed solid or not or if they are encrypted or not). The only way that you can avoid having to decompress the files is if they are added with the store method (ie, not compressed at all, just globbed together).
It seems that it's not possible with 7z out-of-the-box, without decompressing it to a temporary storage.
I hope there is a nice solution that someone will post to solve this (thus the bounty I started).
it's possible for .gz files:
zgrep "hello" foo.txt.gz
it's possible for .xz files:
xzgrep "hello" foo.txt.xz
Note that .xz files use the same compression algorithm than .7z, LZMA2, but it only compresses one file and not many files, except if you use tar (but that's out of topic here).
Conclusion: if you want to archive with a good compression ratio (similar to 7z), in a format that is searchable easily from command-line, use .xz instead of .7z.