Last active
April 25, 2021 07:17
-
-
Save ronanguilloux/8319847 to your computer and use it in GitHub Desktop.
batch in bash to replace accents in filenames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# slugify.sh by Ronan | |
# | |
# Distributed under terms of the MIT license. | |
# | |
cd photos | |
for file in *.png; do | |
filename=${file%.*} | |
#file_clean=`echo $filename | tr -cs "[:alnum:]_" _ ` | |
#file_clean=`echo $filename | iconv -c -f utf8 -t ascii` | |
#file_clean=`echo $filename | iconv -f utf8 -t ascii//TRANSLIT | iconv -c -f utf8 -t ascii` | |
file_clean=`echo $filename | iconv -f utf8 -t ascii//TRANSLIT` | |
final="$file_clean.png" | |
echo "mv \"$file\" \"$final\" " | |
done | |
cd .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I generalized your script as follows:
echo $1
find $1 -regextype posix-egrep -regex '.[{ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜ].' | while read filename; do
file_clean=
echo $filename | iconv -f utf8 -t ascii//TRANSLIT
mv -n "$filename" "$file_clean"
echo "$file_clean"
done
Hope this helps someone.