I want to grep for today's date from zip file. How can do this?
I have a zip file called sen2616.z I want to get all the data for today's date 09.02.2014
Please use zipgrep
.
zgrep
is for gz files, not for zip files.
zipgrep
is that it prints only the name of the matching file within the .zip
archive, and not the name of the .zip file itself. This is probably what you want when you're searching through a single file, but when searching recursively, this info is useless, since you don't know which .zip file matched. I had to use something like $ for f in $(find .) ; do zipgrep -l <pattern> $f && echo $i ; done
which more or less does the job.
echo
so I discarded the idea. The above one liner of a shell "script" was much easier, though surely less efficient than changing the actual zipgrep
script. Also note that changing the original script under /usr/bin
can be problematic with updates of your distro, since it will either overwrite your change, or detect the change and ask what you want to do about it.
In my case zgrep
didn't work on a normal .zip
file. I had to use zipgrep
instead.
zipgrep
is provided by the unzip
package.
You can use zgrep
to get what you want, with:
zgrep '09.02.2014' myfile.zip
See man zgrep
for more info.
zgrep
silently failed for me on a zip file: it gave no error/warning message, and returned only a subset of the matches! Had to use zipgrep
.
zgrep
does not "silently fail" - it just does not print anything if it doesn't find anything. And it doesn't find anything, because it treats your .zip archive as a normal binary file (since it's not gzip).
zipgrep
will work with zip files only.
If you want to grep all files, not only zipped files, then you could use ugrep, which allows to do that with -z
flag.