Skip to content

Instantly share code, notes, and snippets.

@tcarreira
Last active June 28, 2020 18:31
Show Gist options
  • Save tcarreira/55ad5cd1882127f87fe675cbf473ce47 to your computer and use it in GitHub Desktop.
Save tcarreira/55ad5cd1882127f87fe675cbf473ce47 to your computer and use it in GitHub Desktop.
Convert windows encoding (ISO-8859-15) to utf8 (with backups)
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