7

In order to make this conversion I have to use a text editor. This is tedious. Is there an easier way to do it, like some program I can run from the Linux or OS X terminal?

1
  • If your target is Window's Shift_JIS, you should use CP932 instead if you are having problems converting some characters.
    – lepe
    Jun 6, 2013 at 3:08

2 Answers 2

14

To convert from Shift JIS to UTF-8 on linux just do:

iconv -f SHIFT-JIS -t UTF-8 <infile> > <outfile>

and to go the other way just reverse the arguments:

iconv -f UTF-8 -t SHIFT-JIS <infile> > <outfile>

I don't know OSX but it may well have the iconv command as well, in which case something similar should work.

2
  • iconv -f UTF-16 -t SHIFT-JIS part2errorfirst.txt > jjjjjjjjjj.txt is leading to garbled text- i.imgur.com/Z4H8v29.png Apr 2, 2016 at 9:42
  • converted a file using iconv -f UTF-16 -t SHIFT_JIS prt1shift.txt > jjjjjjjjjj.txt, and instead of SHIFT_JIS it got converted into Western(ISO-8859-15) with all the JP characters converted to boxes Apr 2, 2016 at 10:28
0

I use the following command:

SHIFT-JIS to UTF-8

nkf -w <infile> > <Outfile>

UTF-8 to SHIFT-JIS

nkf -s <infile> > <Outfile>

NKF - Network Kanji code conversion Filter

3
  • I am trying to convert a file in utf-8 to shift-JIS. But it doesn't work as expected. The resulting file has weird characters in it, instead of Japanense ones. All the JP characters are garbled - imgur.com/sbibRAT Apr 2, 2016 at 9:34
  • converted a file using nkf -s prt1shift.txt > klklklklklk.txt, and instead of SHIFT_JIS it got converted into Western(ISO-8859-15) with all the JP characters converted to boxes Apr 2, 2016 at 10:30
  • @vipin8169 Sorry for the too late reply but just in case others are reading the answer. What is the terminal used to view the resulting file. It is possible that the file conversion works since the box your in has the nkf command but the actual terminal client has a wrong encoding. One common case of this is the TeraTerm, you may have used other encoding as the input/output encoding for the client. Just a suggestion.
    – Nassign
    Feb 14, 2020 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .