Last active
June 28, 2020 18:31
-
-
Save tcarreira/55ad5cd1882127f87fe675cbf473ce47 to your computer and use it in GitHub Desktop.
Convert windows encoding (ISO-8859-15) to utf8 (with backups)
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
OLDIFS=$IFS | |
IFS=$'\n' | |
prefix=".old.conv.$(date +%Y%m%d_%H%M%S)" | |
for file in $(find . -type f -name '*.php*') ; do | |
if file "$file" | grep "ISO-8859 text" 2>/dev/null; then | |
echo "convert;${file};$(file $file)" | |
dir=$(dirname "$file") | |
filename=$(basename "$file") | |
bakfile="${dir}/${prefix}.${filename}" | |
mv "$file" "${bakfile}" | |
iconv -f ISO-8859-15 -t utf8 -o "$file" "${bakfile}" | |
else | |
echo "skipinn;${file};$(file $file)" | |
fi | |
done | |
IFS=$OLDIFS | |
# In the end, to delete the backup files, run: | |
# find . -name ".old.conv.20200628_183042*" -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment