Encodage fichiers
De Linuxmemo.
Version du 4 mai 2012 à 09:59 par Linuxmemo (discuter | contributions)
Connaître l'encodage d'un fichier
- file
file -i nom_fichier
changer l'encodage
- iconv
iconv -f oldcode -t newcode entree -o sortie
oldcode : l'encodage du fichier d'origine
newcode : l'encodage souhaité
entree : le fichier d'origine
sortie : le fichier souhaité
Pour voir la liste des encodages disponibles dans iconv, vous pouvez taper la commande suivante : iconv -l
Ce type d'outil m'est extrêmement utile, notamment pour les fichiers HTML. Attention cependant le fichier ainsi converti doit être ouvert pour modifier l'attribut charset :
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> en charset="UTF-8".
- recode
La commande recode bien que plus complexe est également très intéressante pour convertir des fichiers HTML (encodage/décodage des entités par exemple).
recode -l | less Show available conversions (aliases on each line) recode windows-1252.. file_to_change.txt Windows "ansi" to local charset (auto does CRLF conversion) recode utf-8/CRLF.. file_to_change.txt Windows utf8 to local charset recode iso-8859-15..utf8 file_to_change.txt Latin9 (western europe) to utf8 recode ../b64 < file.txt > file.b64 Base64 encode recode /qp.. < file.qp > file.txt Quoted printable decode recode ..HTML < file.txt > file.html Text to HTML recode -lf windows-1252 | grep euro Lookup table of characters echo -n 0x80 | recode latin-9/x1..dump Show what a code represents in latin-9 charmap echo -n 0x20AC | recode ucs-2/x2..latin-9/x Show latin-9 encoding echo -n 0x20AC | recode ucs-2/x2..utf-8/x Show utf-8 encoding
- vim
$ vim file :set bomb ou bien :set nobomb :set fileencoding=utf-8 :wq
- xxxxx
conversion vers UTF-8 (sans BOM) par lot