-
-
Save antenando/fc2a806d1067038fb691d0a8f9a16803 to your computer and use it in GitHub Desktop.
Shell script to convert encoding of files to utf-8.
This file contains hidden or 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 | |
if [ $# -lt 1 ] | |
then | |
echo "Usage: "$0" <file_name>" | |
echo "Convert files to utf-8" | |
exit | |
fi | |
for i in $* | |
do | |
encoding=$(chardet $i | cut -d ' ' -f 2) #determine the encoding of current file | |
echo "encoding "$i" ("$encoding") to utf-8" | |
iconv -f $encoding -t utf-8 $i -o $i.tmp #tmp file is created as a workaround for bus error | |
mv $i.tmp $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment