Linux : Convertir UNICODE UTF-16 en UTF-8
Voici une méthode simple et rapide pour convertir des fichiers UTF-16 issus du monde Windows :
Afin d’avoir plus d’informations sur le fichier, nous allons utiliser file :
file 20120513_chat.log 20120513_chat.log: Little-endian UTF-16 Unicode English text, with CRLF line terminators |
Nous avons bien à faire à un fichier encodé en UTF-16 il va donc falloir le convertir en UTF-8 avec iconv :
iconv -f UTF-16 -t UTF-8 -o fichier_de_sortie.log 20120513_chat.log |
Si on ré-exécute file avec le fichier obtenu :
file fichier_de_sortie.log UTF-8 Unicode English text, with CRLF line terminators |
Il est réencodé en UTF-8 et va permettre l’utilisation de grep 🙂