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