Bash to group files by name and zip them
Hello,
I am looking for a way to go through a folder containing image files and ZIP them based on a substring. I started doing this using Applescript and Automator, but this was a very slow process. I came across the following Bash command Code:
for i in *.JPG; do zip "${i%.*}.zip" "${i%.*}".*; done Code:
for q in *_*.JPG; do mkdir -p "${q%_*}"; mv "$q" "${q%_*}"; done As a programming newbie, what can I change in the ZIP command to achieve grouping the files and zipping them. The file names consist of an object number, following by underscore and a running number which may be up to three digits depending on the files concerning a specific object number (e.g., XYZ04999_01.jpg, XYZ04999_02.jpg, XYZ04999_03.jpg, etc.). I'd be grateful for some help. Thank you! |
A slight variant would be the standard tar archive:
Code:
for q in *_*.jpeg; do |
FYI, zip works like tar -append by default adding new files to an existing archive if specified on the command line, so the tar line above could be rewritten as
Code:
zip "${q%_*}.zip" ${q} |
A side issue: JPGs are already compressed; zipping a group of them together might be useful, but it will compress only marginally.
|
All times are GMT -5. The time now is 10:17 PM. |