am new to grep so please take it easy thanks. here is what i have,i have a folder with 1000 .zip files small sizes and i want to search all them using a string and if it matches then extract only the matched string to another folder.

grep "u74" *.zip

ok the code above i i placed 1 zip file in grep folder and searched for u74 and it matches.

how do i make a search.bat and leave all zip in their original folder rather then moving them to grep folder. my grep installation folder

C:\Program Files (x86)\GnuWin32\bin

here are some codes i found but its not working

for i in *.zip; do 
    echo "scanning $i";
grep -oP "u74" <(unzip -l "$i") && echo "Found in $i" || echo "Not Found in $i"; 

this is exactly what i want but its not working lastly i want to create a folder in same zip path and found and move all found files their.

  • 1
    The script you found is clearly shell script, not BATCH script. You can install cygwin and do it from there, it'll be much easier. – SparedWhisle Sep 5 '19 at 3:20

the way you propose to use grep in your question means that it would find the string "u74" in the compressed data.

The Unix/Linux script you found (as observed by David, it won't run on Win) solves this problem by unzipping every zip in a subprocess, that is the (unzip -l ...) part.

Short of installing cygwin or python for Windows, what you can do is unpack all zips into a location like D:\My_Data and then either

grep "u74" D:\My_Data\*.*


you cd into D:\My_Data and from there you run

C:\Program Files (x86)\GnuWin32\bin\grep "u74" *.*

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.