Skip to content

Instantly share code, notes, and snippets.

@s4l1h
Last active January 25, 2017 23:15
Show Gist options
  • Select an option

  • Save s4l1h/7f7d86b65467441487290ec76dccf838 to your computer and use it in GitHub Desktop.

Select an option

Save s4l1h/7f7d86b65467441487290ec76dccf838 to your computer and use it in GitHub Desktop.
Multiple File Encoding Conversion Raw
#!/bin/bash
# Test On Mac OS X
#
#enter input encoding here
FROM_ENCODING="ISO-8859-9"
#output encoding(UTF-8)
TO_ENCODING="UTF-8//TRANSLIT"
#convert
#iconv -f ISO-8859-9 -t UTF-8//TRANSLIT index.php -o index.php.utf8
CONVERT="iconv -f $FROM_ENCODING -t $TO_ENCODING"
#loop to convert multiple files
for file in *.php; do
$CONVERT "$file" > "$file.utf8" #mac
# $CONVERT "$file" -o "$file.utf8" #linux
done
exit 0
#mv index.php.utf8 index.php
for filename in *.utf8; do
[ -f "$filename" ] || continue
mv $filename ${filename//\.utf8/}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment