When I use iconv to convert from UTF16 to UTF8 then all is fine but vice versa it does not work. I have these files:
a-16.strings: Little-endian UTF-16 Unicod
I first convert to UTF-16
, which will prepend a byte-order mark, if necessary as Keith Thompson mentions. Then since UTF-16
doesn't define endianness, we must use file
to determine whether it's UTF-16BE
or UTF-16LE
. Finally, we can convert to UTF-16LE
.
iconv -f utf-8 -t utf-16 UTF-8-FILE > UTF-16-UNKNOWN-ENDIANNESS-FILE
FILE_ENCODING="$( file --brief --mime-encoding UTF-16-UNKNOWN-ENDIANNESS-FILE )"
iconv -f "$FILE_ENCODING" -t UTF-16LE UTF-16-UNKNOWN-ENDIANNESS-FILE > UTF-16-FILE