I am using 'find' and 'grep' cygwin commands in order to locate files based on some pattern. I am doing this:

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

It works fine and I have file name with 'vbs' in file name. BUT now I need to do similar but I need to find the file name based on the content of it e.g. 'vbs' is not part of the file name but part of the file content. How it could be modified? Maybe something like :

find . -iname '*.zip' -print -exec unzip -l {} \; 2> error.txt | xargs ??? Could someone advice? Thanks


Since you are going to grep the file content, -l listing the zip file won't be enough. you need to actually unzip it. so:

temp=`mktemp -d`    
find . -iname '*.zip' -print -exec unzip -d $temp {} \; 2> error.txt
grep -ir vbs $temp   
  • Well ... It doesn't work that way, I've got this error: grep: unknown option -- ------- Usage: grep [OPTION]... PATTERN [FILE]... Try 'grep --help' for more information. grep: unknown option -- ------- – susik Jun 22 '16 at 14:20

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.