29

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.

Łukasz Bensz
  • 391
  • 1
  • 3
  • 5
  • It looks like iconv from utf-8 to iso doesn't works with some specific Unicode characters. I have used the option --unicode-subst=formatstring and it works, not the perfect solution but satisfactory – Łukasz Bensz Apr 28 '15 at 15:12
  • What version of iconv supports "--unicode-subst"? – AdamC Jul 29 '15 at 18:16
  • iconv --version iconv (GNU libc) 2.12 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Ulrich Drepper. – Łukasz Bensz Jul 31 '15 at 23:33

3 Answers3

25

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
choroba
  • 231,213
  • 25
  • 204
  • 289
14

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
peak
  • 105,803
  • 17
  • 152
  • 177
4

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

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

Sebastian Piskorski
  • 4,026
  • 3
  • 23
  • 29