-1

I have a zip file where each file is named the following

original.jpg.1.png
original.jpg.2.png

The files are actually jpegs How do I go about renaming them to the following?

original1.jpg
original2.jpg

closed as unclear what you're asking by Jeff Schaller, mosvy, Michael Homer, jimmij, Thomas Mar 9 at 9:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Wait, I completely missed an important word here; you have zip files that contain these filenames. Do you want to extract the zip file(s) to new filenames, or do you want to (end up with) renamed files inside the zip file? Or do you just have plain directories? – Jeff Schaller Mar 8 at 15:39
  • As the hint of the downarrow says: This question does not show any research effort. – Juan Mar 8 at 15:48
2

With prename (perl rename):

rename 's/original.jpg.(\d+).png/original$1.jpg/' original.jpg.*.png
0

I was able to accomplish this with the following bash script:

#!/bin/bash

#Location of the zip file
zip_file="/path/to/jpegs.zip"
#Desired location of extracted files
dest_dir="/path/to/extract"

#Unzip the file to the desired location
unzip "$zip_file" -d "$dest_dir"

for f in "$dest_dir/"*.png; do
    #Remove path from filename.
    filename=$(basename "$f")
    #Remove .jpg. from filename.
    filename=${filename/.jpg./}
    #Change .png to .jpg
    filename=${filename/.png/.jpg}
    #Rename the extracted files to the preferred naming convention using mv.
    mv "$f" "${dest_dir}/${filename}"
done

Not the answer you're looking for? Browse other questions tagged or ask your own question.