Skip to content

Instantly share code, notes, and snippets.

@Tafkadasoh
Last active August 29, 2015 13:56
Show Gist options
  • Save Tafkadasoh/9041833 to your computer and use it in GitHub Desktop.
Save Tafkadasoh/9041833 to your computer and use it in GitHub Desktop.
For customers of the German Postbank who are annoyed that the filename of their account current PDF is very cryptic. Especially annoying to me was that the date in the filename is DD-MM-YYYY opposed to YYYY-MM-DD. Use this little bash script to rename the files. Note: As I only have one bank account, I remove the account number from the filename…
#!/bin/bash
# Benennt Dateinamen von Kontoauszügen der Deutschen Postbank in ein lesbares Format um.
# z.B.: "PB_KAZ_KtoNr_0123456789_01-02-2014_0343.pdf" --> "kontoauszug_2014-02-01.pdf"
# Allgemein: "PB_KAZ_KtoNr_0123456789_DD-MM-YYYY_0123.pdf" --> "kontoauszug_YYYY-MM-DD.pdf"
SRCPREFIX="PB_KAZ_KtoNr_"
SRCSUFFIX=".pdf"
DESTPREFIX="kontoauszug_"
DESTSUFFIX=".pdf"
for i in *.pdf; do
if [[ $i =~ ^$SRCPREFIX([0-9]*)_([0-9]{2})-([0-9]{2})-([0-9]{4})_.*$SRCSUFFIX$ ]]; then
x="$DESTPREFIX${BASH_REMATCH[4]}-${BASH_REMATCH[3]}-${BASH_REMATCH[2]}$DESTSUFFIX"
# Uncomment the next line if you want to keep the bank account number.
# x="$DESTPREFIX${BASH_REMATCH[1]}_${BASH_REMATCH[4]}-${BASH_REMATCH[3]}-${BASH_REMATCH[2]}$DESTSUFFIX"
echo "Renaming $i to $x ..."
mv $i $x
fi
done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment