Skip to content

Instantly share code, notes, and snippets.

@leoluyi
Forked from arpith20/convert-encoding.sh
Created January 30, 2018 03:57
Show Gist options
  • Select an option

  • Save leoluyi/85b45a3a750fb6f1d8cab0ea8203320d to your computer and use it in GitHub Desktop.

Select an option

Save leoluyi/85b45a3a750fb6f1d8cab0ea8203320d 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