Skip to content

Instantly share code, notes, and snippets.

@sistematico
Last active March 20, 2016 18:57
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 sistematico/6047b4a7f454291e19eb to your computer and use it in GitHub Desktop.
Save sistematico/6047b4a7f454291e19eb to your computer and use it in GitHub Desktop.
Conversão de arquivos para UTF-8
#!/bin/sh
cod1="utf-8"
for arquivo in $*; do
if [ "$(file --mime-type ${arquivo} | cut -d ' ' -f2)" == "text/plain" ]; then
cod2=$(file --mime-encoding ${arquivo} | cut -d ' ' -f2)
if [ "$cod2" != "$cod1" ]; then
echo "Convertendo o $arquivo de $cod2 para ${cod1}..."
iconv -f $cod2 -t $cod1 "$arquivo" -o "${arquivo}.tmp"
mv $arquivo $arquivo.old
mv $arquivo.tmp $arquivo
else
echo $arquivo já está em $cod1
fi
else
echo "Tipo de arquivo inválido."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment