Skip to content

Instantly share code, notes, and snippets.

@Saafke
Last active July 8, 2021 09:57
Show Gist options
  • Save Saafke/8166ead1984ae3e7239b0f8e51c1a619 to your computer and use it in GitHub Desktop.
Save Saafke/8166ead1984ae3e7239b0f8e51c1a619 to your computer and use it in GitHub Desktop.
Subtracts a number from filenames with a number in them (no leading zeros). For example: out321.png -> out300.png if NUMBER_TO_SUBTRACT=21
NUMBER_TO_SUBTRACT=217
for file in `ls -1v out*`; do
echo $file
NUMBER=${file:3:-4}
NEW_NUMBER=$[NUMBER-NUMBER_TO_SUBTRACT]
NEW_FILE_NAME="out${NEW_NUMBER}.png"
echo $NEW_FILE_NAME
mv $file $NEW_FILE_NAME
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment