I have to find some text inside zipped files. I am using Cygwin. Some zipped files are empty. Obviously I don't want to have 'noisy' information about those 'empty zip files' at all. E.g.

find . -iname '*.zip' -print -exec unzip -l {} \; |grep -i vbs

Where vbs is a string I'm searching for.

The problem is that it returns what I'm looking for but it also returns a lot of noise with lines like this:

warning [/z/XYZ/Backup/123/456/Backup Set 1/Backup Files 1/Backup files 2.zip]:  zipfile is empty

I don't want to see those lines with 'zipfile is empty'

I tried to pipe it with |grep -v 'zipfile is empty' but it still outputs those lines as well.

My question: how can I avoid printing those 'empty' lines and see only the lines I'm looking for; i.e., vbs?


Those additional lines are probably in the stderr stream. You could test by seeing if they redirect out to a separate file (e.g. command 2> error.txt)

Basically, run:

find . -iname '*.zip' -print -exec unzip -l {} \; 2> error.txt |grep -i vbs 

If this fixes your problem, you can replace error.txt with /dev/null (this may not work on all versions of cygwin)

  • Thanks for reply but redirecting to 2> did not make any difference i.e. file error.txt get created, it's empty and I still have printed a lot of 'empty' lines, Any other suggestion? Thanks – susik Jun 20 '16 at 13:40
  • - Jedi, thanks so much, Not it works perfect. The last one request: current implementation find . -iname '*.zip' -print -exec unzip -l {} \; 2> error.txt |grep -i vbs ... will match pattern in the file name. BUT in most cases I need to find file based on the content e.g. vbs is not a part of the file name but part of the file content. Could you help me i.e. enable to search based on file content. Thanks again and appreciate your help – susik Jun 21 '16 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.