how to find files matching a pattern and zip

Hi,

I want to find all directories matching given pattern in current directory and zip those files.

I am trying to do somethign like this. But it is not working.

 
 
for FNAME in $(find . -type d | grep './[0-9]\{2\}-[0-9]\{2\}$');
do
  zip -r MatchedFiles.zip $FNAME
  rm -fr $FNAME
done 

I am getting $ unexpected.
In above code find and grep working fine. But How can i loop through the results of find|grep command results.

double quote around "$FNAME" ?

Lower latency, no line length limit, economy of scale (Hope the -r and -@ are compatible!):

find . -type d | grep './[0-9]\{2\}-[0-9]\{2\}$' | zip -rmTg MatchedFiles.zip -@

or more simply:

zip -rmTg MatchedFiles.zip ./[0-9][0-9]-[0-9][0-9]/
1 Like

The error message means that you are not running a modern Shell. Might be an old Bourne Shell.

It doesn't like the $(command) syntax.

What Operating System and Shell do you have?
Do you have the option to use "ksh" , "bash" or a Posix shell ?

1 Like

You are right. I was running in sh. when i changed it to bash it worked fine.

Thanks a lot.

The alternate script you provided worked like a charm. Thanks.