Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 202
Łukasz Bensz Avatar asked Apr 28 '15 15:04

Łukasz Bensz


People also ask

How do I convert UTF-8 to ISO 8859-1?

Going backwards from UTF-8 to ISO-8859-1 will cause "replacement characters" (�) to appear in your text when unsupported characters are found. byte[] utf8 = ... byte[] latin1 = new String(utf8, "UTF-8"). getBytes("ISO-8859-1"); You can exercise more control by using the lower-level Charset APIs.

Is ISO 8859 the same as UTF-8?

UTF-8 is a multibyte encoding that can represent any Unicode character. ISO 8859-1 is a single-byte encoding that can represent the first 256 Unicode characters. Both encode ASCII exactly the same way.


1 Answers

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 
like image 153
choroba Avatar answered Sep 21 '22 18:09

choroba