Skip to content

Instantly share code, notes, and snippets.

@aheusingfeld
Created January 3, 2017 16:50
Show Gist options
  • Save aheusingfeld/64705381fd9fb013d5a65b62e4fdd38f to your computer and use it in GitHub Desktop.
Save aheusingfeld/64705381fd9fb013d5a65b62e4fdd38f to your computer and use it in GitHub Desktop.
Replace german special chars in file and folder names
#!/bin/bash
# This replaces german special chars in all files and folder under the specified folder
# Call this via "./replace_spec_chars.sh `pwd`"
#
# PREREQUISITES: make sure to have the `rename` command installed which accepts perl regexs
TARGET_FOLDER=$1
CURR_DIR=`pwd`
# make sure to preserve spaces in file and folder names
while IFS= read -d $'\0' -r CURRENT_FOLDER; do
# just For debugging, print current directory
#echo $CURRENT_FOLDER
cd "$CURRENT_FOLDER"
# switch LATIN1 chars over to UTF8
rename 'BEGIN {binmode STDIN, ":encoding(latin1)"; use Encode;} $_=encode("utf8", $_)' *
rename 's/ä/ae/' *
rename 's/ö/oe/' *
rename 's/ü/ue/' *
rename 's/ß/ss/' *
done < <(find $TARGET_FOLDER -mindepth 1 -maxdepth 8 -type d -print0)
cd $CURR_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment