Skip to content

Instantly share code, notes, and snippets.

@IsakViste
Last active October 31, 2022 13:10
Show Gist options
  • Save IsakViste/ff2fc41ad8495e1539447d640f305365 to your computer and use it in GitHub Desktop.
Save IsakViste/ff2fc41ad8495e1539447d640f305365 to your computer and use it in GitHub Desktop.
Script: Replace spaces in IPTC Headline tag of RAW Images with underscore
#!/bin/bash
cd "$PWD"
if [ -z "$1" ]; then
read -e -p "Image Extension: " EXTENSION
else
EXTENSION="$1"
fi
BACKUP_FOLDER=ORIGINALS_$(date +%Y%m%d-%H%M%S)
mkdir "$BACKUP_FOLDER"
for image in *.${EXTENSION}; do
name=`exiftool -s3 -iptc:Headline $image`
new_name=${name// /_}
if [ "$name" != "$new_name" ]; then
exiftool -iptc:Headline="$new_name" "$image"
original_file="${image}_original"
if [ -f "$original_file" ]; then
mv -vn "$original_file" "$BACKUP_FOLDER"
fi
echo "[$image]"
echo "$(exiftool -iptc:Headline "$image")"
echo ""
fi
done
if [ -z "$(ls -A $BACKUP_FOLDER)" ]; then
rmdir "$BACKUP_FOLDER"
fi
#!/bin/bash
cd "$PWD"
if [ -z "$1" ]; then
read -e -p "Backup Folder: " TARGET_FOLDER
else
TARGET_FOLDER="$1"
fi
BACKUP_FOLDER=$(echo $TARGET_FOLDER | sed 's:/*$::')
cd "$BACKUP_FOLDER"
for image in *.*_original; do
new_name=${image/_original/}
mv -v "$image" "../$new_name"
echo "[$new_name] Headline: $(exiftool -s3 -iptc:Headline "../$new_name")"
echo ""
done
cd ..
if [ -z "$(ls -A $BACKUP_FOLDER)" ]; then
rmdir "$BACKUP_FOLDER"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment