Skip to content

Instantly share code, notes, and snippets.

@arpith20
Created January 13, 2017 08:50
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save arpith20/4fcf7682a9154bc777dfcd2199edecf4 to your computer and use it in GitHub Desktop.
Save arpith20/4fcf7682a9154bc777dfcd2199edecf4 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