1

I know this has been covered over the years but no harm in an update perhaps there are more expedient techniques.

I have approx 1 terabyte of Canon CR2 images in 40 sub-folders, some with matching jpeg and some just jpeg.

I want to delete all jpegs that have a matching corresponding raw .cr2 file.

I would like to mac automator or a script run through terminal.

I tried some of the tips from an older article but the scripts has syntax errors.

How to delete JPG files, but only if the matching RAW file exists?

I get an error Expected end of line, etc. but found “"”.

apologies but the syntax error persists

#!/bin/bash
read -p "*.CR2" suffix

find . -type f -iname "*.${suffix}" |
while read line do lowercase=$(echo "$line" | sed "s/${suffix}/jpg/gi") uppercase=$(echo "$line" | sed "s/${suffix}/JPG/gi")

if [ -f "${lowercase}" ] then rm -v "${lowercase}" elif [ -f "${uppercase}" ] then rm -v "${uppercase}" else echo "${line}: no jpg present" fi done

Romeo Ninov
  • 12,030
  • 4
  • 31
  • 49
PatZuri
  • 11
  • 2
  • 1
    How you can be sure the files (CR2 and JPEG) are the same? Compare content? – Romeo Ninov Dec 11 '20 at 08:49
  • Exif data can be compared, the timestamps are equal for both jpeg and raw files. – PatZuri Dec 11 '20 at 09:08
  • EXIF data is just text included in to the file. There is no problem to copy EXIF records from one file and write them to another file. – Romeo Ninov Dec 11 '20 at 09:13
  • 2
    I understand you saw this question already, but syntax errors are not a reason to pose a duplicate question. Can you indicate what the syntax errors are? Maybe you can do so in chat? – Saaru Lindestøkke Dec 11 '20 at 10:01
  • 1
    If you specifically require an Automator action, perhaps this question would be better asked at the Apple Stack, [apple.se]. Otherwise, I'm inclined to agree this is a duplicate of the linked question. I won't close this question as a dupe (I'll let the community decide if it's a dupe). If you want us to migrate this to [apple.se], just ask (rather than cross-post over there), we'll make it happen. Thanks. =) – scottbb Dec 11 '20 at 17:35
  • Will be wise to ask programming questions in Stack Overflow https://stackoverflow.com/ – Romeo Ninov Dec 11 '20 at 17:53
  • Thanks I have posted the question on ask different https://apple.stackexchange.com/questions/408672/how-to-create-an-automator-workflow-application-to-delete-jpeg-when-raw-exist – PatZuri Dec 12 '20 at 11:09

0 Answers0