Hello, I need to do the file encoding conversion to utf-8 since the application will migrate from server.
In this application I have files with several encodings in fact, some in utf-8, others in iso-8859-1 and still files in windows-1252.
What I need to do is to migrate all to utf8. I was able to find this bash that does it. The problem is that it adds a blank line after each line of the file, in case if I have a file with 200 line, it turns to 400 leaving the whole code messy and difficult to understand.
I would like to know what I can do to avoid this blank line that it adds.
Here is the code I have to do this conversion:
#!/bin/bash
DIRETORIO=$1
LISTA="/tmp/lista-conversor.txt"
if [ -d "${DIRETORIO}" ]; then
echo -e "\nGerando lista de arquivos em \"${DIRETORIO}\" a serem analisados:\n"
find ${DIRETORIO} -type f > ${LISTA}
#-exec $DIRETORIO {} \;
while read ARQUIVO;do
ISO_YES=$(file $ARQUIVO|grep 8859|wc -l)
if [ "$ISO_YES" -eq 1 ]; then
echo "iso-8859 detectado em $ARQUIVO"
iconv -f iso-8859-1 -t utf-8 ${ARQUIVO} > ${ARQUIVO}.new && echo -e "Arquivo ${ARQUIVO} convertido com sucesso\n"
cp $ARQUIVO ${ARQUIVO}.bkp
mv ${ARQUIVO}.new ${ARQUIVO}
fi
done < ${LISTA}
else
echo -e "Informe um diretorio\n\nEx:\n${0} <diretorio>"
fi