Skip to content

Instantly share code, notes, and snippets.

@antenando
Forked from arpith20/convert-encoding.sh
Created August 14, 2018 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antenando/fc2a806d1067038fb691d0a8f9a16803 to your computer and use it in GitHub Desktop.
Save antenando/fc2a806d1067038fb691d0a8f9a16803 to your computer and use it in GitHub Desktop.
Shell script to convert encoding of files to utf-8.
#!/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