Voglio usare iconv per convertire i file sul mio Mac. L’objective è passare da “Windows ANSI” a “qualsiasi cosa che il Blocco note di Windows salva, se si dice di usare UFT8”.
Questo è quello che voglio:
anders-johansen-privats-macbook-pro:test andersprivat$ file names.csv names.csv: UTF-8 Unicode (with BOM) text, with CRLF line terminators
Questo è quello che uso:
iconv -f CP1252 -t UTF-8 names.csv > names.utf8.csv
Questo è quello che ottengo (non quello che voglio):
file names.utf8.csv names.utf8.csv: UTF-8 Unicode text, with CRLF line terminators
Come ottengo il BOM?
Puoi aggiungerlo manualmente facendo prima echo
i byte nel file:
echo -ne '\xEF\xBB\xBF' > names.utf8.csv
e quindi concatenare le informazioni richieste alla fine:
iconv -f CP1252 -t UTF-8 names.csv >> names.utf8.csv
Nota il >>
piuttosto che >
.
Notare che “Windows ANSI” potrebbe non essere CP1252, configurato dagli utenti.
Avevo bisogno dell’opossita. (testo tedesco nascosto da UTF-8 ad ANSI)
Quindi il comando che ho usato:
1. iconv -l (controlla i formati disponibili)
2. iconv -f UTF8 -t MS-ANSI de.txt> output.txt
e ora se apro output.txt è già in ANSI. Lavoro fatto.