Article 53NGF Bash to group files by name and zip them

Bash to group files by name and zip them

by
Dareios
from LinuxQuestions.org on (#53NGF)
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%.*}".*; donewhich zips each file individually. And I came across this command

Code:for q in *_*.JPG; do mkdir -p "${q%_*}"; mv "$q" "${q%_*}"; doneThe latter makes folders based on the common denominator.

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!latest?d=yIl2AUoC8zA latest?i=e6pBjPMb7uQ:OKD7tpgxvXI:F7zBnMy latest?i=e6pBjPMb7uQ:OKD7tpgxvXI:V_sGLiP latest?d=qj6IDK7rITs latest?i=e6pBjPMb7uQ:OKD7tpgxvXI:gIN9vFwe6pBjPMb7uQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments