Grep files for content

0

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

susik

Posted 2016-06-22T00:47:28.850

Reputation: 447

Answers

1

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   

David Dai

Posted 2016-06-22T00:47:28.850

Reputation: 2 833

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 – 2016-06-22T14:20:36.100