Łukasz Bensz
Łukasz Bensz

Reputation: 401

Why iconv cannot convert from utf-8 to iso-8859-1

My system is SUSE Linux Enterprise Server 11.

I'm trying to convert a data from utf-8 format to iso useing "iconv"

$>file test.utf8
test.utf8: UTF-8 Unicode text, with very long lines
$>
$>file -i test.utf8
test.utf8: text/plain charset=utf-8
$>
$>iconv -f UTF-8 -t ISO-8859-1 test.utf8 > test.iso

iconv: test.utf8:20:105: cannot convert

Could you help me wit this? Thanks.

Upvotes: 30

Views: 45915

Answers (3)

peak
peak

Reputation: 116670

Sometimes it's best to use both -c and //TRANSLIT, e.g.

$ cat rodriguez
Rodrı́guez

$ file rodriguez
rodriguez: UTF-8 Unicode text

$ iconv  --unicode-subst="<U+%04X>" -f UTF-8 -t ISO-8859-1 rodriguez
Rodr<U+0131><U+0301>guez

$ iconv -f UTF-8 -t ISO-8859-1 rodriguez
Rodr
iconv: rodriguez:1:4: cannot convert

$ iconv -f UTF-8 -t ISO-8859-1//TRANSLIT rodriguez
Rodri
iconv: rodriguez:1:5: cannot convert

$ iconv -c -f UTF-8 -t ISO-8859-1 rodriguez
Rodrguez

$ iconv -c -f UTF-8 -t ISO-8859-1//TRANSLIT rodriguez
Rodriguez

Upvotes: 14

Ssss Ppppp
Ssss Ppppp

Reputation: 4404

Use //TRANSLIT parameter and the dummy characters will be put.

iconv -f UTF-8 -t ISO-8859-1//TRANSLIT test.utf8 > test.iso

Upvotes: 5

choroba
choroba

Reputation: 241768

Your input file contains characters that don't exist in Latin 1. You can use the -c option to skip them:

iconv -c -futf8 -tl1 test.utf8 > test.iso

Upvotes: 26

Related Questions