Skip to content

Instantly share code, notes, and snippets.

@ChrisCummins
Last active February 1, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisCummins/f67b003f1f34d132c443 to your computer and use it in GitHub Desktop.
Save ChrisCummins/f67b003f1f34d132c443 to your computer and use it in GitHub Desktop.
Remove the jpg sidecar files from RAW+JPG imports.
#!/usr/bin/env bash
#
# remove-jpg-sidecars.sh
#
# A script to remove the .jpg sidecar files which are generated by
# cameras capturing in JPG+RAW mode.
#
# How it works:
#
# 1) It generates a list of all dng files in the current directory.
# 2) It generates a list of all jpg files in the current directory.
# 3) It checks for common file names in the two lists.
# 4) It removes the 'jpg' version of common files.
#
set -eu
# Tidy up after ourselves.
function finish {
rm -f .jpgs .dngs .common
}
trap finish EXIT
# Detect files.
echo -n "Detecting dng files ... "
find . -iname '*.dng' | sed -r 's/\.dng$//I' > .dngs
echo "done"
echo -n "Detecting jpg files ... "
find . -iname '*.jpg' | sed -r 's/\.jpg$//I' > .jpgs
echo "done"
echo -n "Matching common file names ... "
comm -1 -2 .jpgs .dngs > .common
echo "done"
# Store line counts.
num_jpgs=$(wc -l .jpgs | awk '{print $1;}')
num_dngs=$(wc -l .dngs | awk '{print $1;}')
num_common=$(wc -l .common | awk '{print $1;}')
total=$((num_jpgs+num_dngs))
echo
echo " # of DNGs in library: $num_dngs"
echo " # of JPGs in library: $num_jpgs"
echo " Total library size: $total"
echo
echo " # of JPG sidecars: $num_common"
echo
while true; do
read -p "Do you wish to remove $num_common sidecar jpgs? (yes/no) " yn
case $yn in
[Yy]* )
echo
i=1
while read line; do
if [[ -f "$line.jpg" ]] && [[ -f "$line.dng" ]]; then
jpg=$(find . -ipath "$line.jpg")
echo "($i / $num_common) $jpg"
i=$((i+1))
# Remove the file!
rm "$jpg"
fi
done < .common
break;;
[Nn]* )
exit;;
* )
echo "Please answer yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment