I want to convert CP932 string to UTF-8.
In Ubuntu I can convert string by a command
iconv -f CP932 -t UTF-8 [input_file]
But the iconv in Apline 3.17
fails with a error: iconv: source charset CP932: Invalid argument
.
How can I add CP932 charset to iconv?
The command is called from a ruby script so I don't adhere iconv
if there is better way to convert string CP932
to UTF-8
with ruby or another command line tool in Alpine.
Compile iconv
from source rather than installing it with a package.
apk add --no-cache curl build-base
cd /tmp
curl -O https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz
tar xvf libiconv-1.17.tar.gz
cd libiconv-1.17/
iconv
to /usr/local/bin
:./configure
make
make install
cd /tmp
rm -rf libiconv-1.17/
rm libiconv-1.17.tar.gz
Now you can run iconv
successfully with CP932. Here's an example:
echo "潤" > foo
file -i foo
foo: text/plain; charset=utf-8
iconv -f UTF-8 -t CP932 foo > foo.cp932
file -i foo.cp932
foo.cp932: text/plain; charset=unknown-8bit
and:
cat foo.cp932
��
iconv -f CP932 -t UTF-8 foo.cp932 > foo.utf8
file -i foo.utf8
foo.utf8: text/plain; charset=utf-8
and:
cat foo.utf8
潤
and:
md5sum foo
54282143d705814d6ba671b783f2e0ba foo
md5sum foo.utf8
54282143d705814d6ba671b783f2e0ba foo.utf8