<p>What is the fastest, easiest tool or method to convert text files between character sets?</p>
<p>Specifically, I need to convert from UTF-8 to ISO-8859-15 and vice versa.</p>
<p>Everything goes: one-liners in your favorite scripting language, command-line tools or other utilities for OS, web sites, etc.</p>
<h2>Best solutions so far:</h2>
<p>On Linux/UNIX/OS X/cygwin:</p>
<ul>
<li><p>Gnu <a href="http://www.gnu.org/software/libiconv/documentation/libiconv/iconv.1.html" rel="noreferrer">iconv</a> suggested by <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64889">Troels Arvin</a> is best used <strong>as a filter</strong>. It seems to be universally available. Example:</p>
<pre><code>  $ iconv -f UTF-8 -t ISO-8859-15 in.txt &gt; out.txt
</code></pre>
<p>As pointed out by <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64991">Ben</a>, there is an <a href="http://www.iconv.com/iconv.htm" rel="noreferrer">online converter using iconv</a>.</p>
</li>
<li><p><a href="https://github.com/rrthomas/recode/" rel="noreferrer">recode</a> (<a href="http://www.informatik.uni-hamburg.de/RZ/software/gnu/utilities/recode_toc.html" rel="noreferrer">manual</a>) suggested by <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64888">Cheekysoft</a> will convert <strong>one or several files in-place</strong>. Example:</p>
<pre><code>  $ recode UTF8..ISO-8859-15 in.txt
</code></pre>
<p>This one uses shorter aliases:</p>
<pre><code>  $ recode utf8..l9 in.txt
</code></pre>
<p>Recode also supports <em>surfaces</em> which can be used to convert between different line ending types and encodings:</p>
<p>Convert newlines from LF (Unix) to CR-LF (DOS):</p>
<pre><code>  $ recode ../CR-LF in.txt
</code></pre>
<p>Base64 encode file:</p>
<pre><code>  $ recode ../Base64 in.txt
</code></pre>
<p>You can also combine them.</p>
<p>Convert a Base64 encoded UTF8 file with Unix line endings to Base64 encoded Latin 1 file with Dos line endings:</p>
<pre><code>  $ recode utf8/Base64..l1/CR-LF/Base64 file.txt
</code></pre>
</li>
</ul>
<p>On Windows with <a href="https://learn.microsoft.com/en-us/powershell/" rel="noreferrer">Powershell</a> (<a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64937">Jay Bazuzi</a>):</p>
<ul>
<li><code>PS C:\&gt; gc -en utf8 in.txt | Out-File -en ascii out.txt</code></li>
</ul>
<p>(No ISO-8859-15 support though; it says that supported charsets are unicode, utf7, utf8, utf32, ascii, bigendianunicode, default, and oem.)</p>
<h2>Edit</h2>
<p>Do you mean iso-8859-1 support? Using &quot;String&quot; does this e.g. for vice versa</p>
<pre><code>gc -en string in.txt | Out-File -en utf8 out.txt
</code></pre>
<p>Note: The possible enumeration values are &quot;Unknown, String, Unicode, Byte, BigEndianUnicode, UTF8, UTF7, Ascii&quot;.</p>
<ul>
<li>CsCvt - <a href="http://www.cscvt.de" rel="noreferrer">Kalytta's Character Set Converter</a> is another great command line based conversion tool for Windows.</li>
</ul>

[{'answer_id': 64878, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://linux.die.net/man/1/iconv" rel="noreferrer">iconv(1)</a></p>\n\n<pre><code>iconv -f FROM-ENCODING -t TO-ENCODING file.txt\n</code></pre>\n\n<p>Also there are iconv-based tools in many languages.</p>\n'}, {'answer_id': 64888, 'author': 'Cheekysoft', 'author_id': 1820, 'author_profile': 'https://Stackoverflow.com/users/1820', 'pm_score': 5, 'selected': False, 'text': '<p>Under Linux you can use the very powerful <strong>recode</strong> command to try and convert between the different charsets as well as any line ending issues. <strong>recode -l</strong> will show you all of the formats and encodings that the tool can convert between. It is likely to be a VERY long list.</p>\n'}, {'answer_id': 64889, 'author': 'Troels Arvin', 'author_id': 4462, 'author_profile': 'https://Stackoverflow.com/users/4462', 'pm_score': 8, 'selected': False, 'text': '<p><a href="http://linux.die.net/man/1/iconv" rel="noreferrer">Stand-alone utility</a> approach</p>\n<pre class="lang-none prettyprint-override"><code>iconv -f ISO-8859-1 -t UTF-8 in.txt &gt; out.txt\n</code></pre>\n<pre class="lang-none prettyprint-override"><code>-f ENCODING  the encoding of the input\n-t ENCODING  the encoding of the output\n</code></pre>\n<p>You don\'t have to specify either of these arguments. They will default to your current locale, which is usually UTF-8.</p>\n'}, {'answer_id': 64937, 'author': 'Jay Bazuzi', 'author_id': 5314, 'author_profile': 'https://Stackoverflow.com/users/5314', 'pm_score': 5, 'selected': False, 'text': '<pre><code>Get-Content -Encoding UTF8 FILE-UTF8.TXT | Out-File -Encoding UTF7 FILE-UTF7.TXT\n</code></pre>\n\n<p>The shortest version, if you can assume that the input BOM is correct:</p>\n\n<pre><code>gc FILE.TXT | Out-File -en utf7 file-utf7.txt\n</code></pre>\n'}, {'answer_id': 80494, 'author': 'user15096', 'author_id': 15096, 'author_profile': 'https://Stackoverflow.com/users/15096', 'pm_score': 2, 'selected': False, 'text': '<p>PHP iconv()</p>\n\n<p><code>iconv("UTF-8", "ISO-8859-15", $input);</code></p>\n'}, {'answer_id': 8401721, 'author': 'Arne Evertsson', 'author_id': 16686, 'author_profile': 'https://Stackoverflow.com/users/16686', 'pm_score': 4, 'selected': False, 'text': "<h1>Try iconv Bash function</h1>\n<p>I've put this into <code>.bashrc</code>:</p>\n<pre><code>utf8()\n{\n    iconv -f ISO-8859-1 -t UTF-8 $1 &gt; $1.tmp\n    rm $1\n    mv $1.tmp $1\n}\n</code></pre>\n<p>..to be able to convert files like so:</p>\n<pre><code>utf8 MyClass.java\n</code></pre>\n"}, {'answer_id': 10933885, 'author': 'Jeremy Glover', 'author_id': 524314, 'author_profile': 'https://Stackoverflow.com/users/524314', 'pm_score': 4, 'selected': False, 'text': '<h1>Try Notepad++</h1>\n<p>On Windows I was able to use Notepad++ to do the conversion from <strong>ISO-8859-1</strong> to <strong>UTF-8</strong>. Click <code>&quot;Encoding&quot;</code> and then <code>&quot;Convert to UTF-8&quot;</code>.</p>\n'}, {'answer_id': 17329039, 'author': 'pi3', 'author_id': 478484, 'author_profile': 'https://Stackoverflow.com/users/478484', 'pm_score': -1, 'selected': False, 'text': '<p>As described on <a href="https://stackoverflow.com/questions/132318/how-do-i-correct-the-character-encoding-of-a-file">How do I correct the character encoding of a file?</a> <a href="http://www.synalysis.net" rel="nofollow noreferrer">Synalyze It!</a> lets you easily convert on OS X between all encodings supported by the <a href="http://icu-project.org" rel="nofollow noreferrer">ICU library</a>.</p>\n\n<p>Additionally you can display some bytes of a file translated to Unicode from all the encodings to see quickly which is the right one for your file.</p>\n'}, {'answer_id': 32861628, 'author': 'Boop', 'author_id': 2282427, 'author_profile': 'https://Stackoverflow.com/users/2282427', 'pm_score': 7, 'selected': False, 'text': '<h1>Try VIM</h1>\n<p>If you have <code>vim</code> you can use this:</p>\n<p>Not tested for every encoding.</p>\n<p>The cool part about this is that you don\'t have to know the source encoding</p>\n<pre><code>vim +&quot;set nobomb | set fenc=utf8 | x&quot; filename.txt\n</code></pre>\n<p>Be aware that this command modify directly the file</p>\n<hr />\n<h3>Explanation part!</h3>\n<ol>\n<li><code>+</code> : Used by vim to directly enter command when opening a file. Usualy used to open a file at a specific line: <code>vim +14 file.txt</code></li>\n<li><code>|</code> : Separator of multiple commands (like <code>;</code> in bash)</li>\n<li><code>set nobomb</code> : no utf-8 BOM</li>\n<li><code>set fenc=utf8</code> : Set new encoding to utf-8 <a href="https://vimhelp.org/options.txt.html#%27fileencoding%27" rel="noreferrer">doc link</a></li>\n<li><code>x</code> : Save and close file</li>\n<li><code>filename.txt</code> : path to the file</li>\n<li><code>&quot;</code> : qotes are here because of pipes. (otherwise bash will use them as bash pipe)</li>\n</ol>\n'}, {'answer_id': 39195151, 'author': 'Serge Stroobandt', 'author_id': 2192488, 'author_profile': 'https://Stackoverflow.com/users/2192488', 'pm_score': 4, 'selected': False, 'text': '<h1>Oneliner using find, with automatic character set detection</h1>\n<p><strong>The character encoding</strong> of all matching text files <strong>gets detected automatically</strong> and all matching text files are converted to <code>utf-8</code> encoding:</p>\n<pre><code>$ find . -type f -iname *.txt -exec sh -c \'iconv -f $(file -bi &quot;$1&quot; |sed -e &quot;s/.*[ ]charset=//&quot;) -t utf-8 -o converted &quot;$1&quot; &amp;&amp; mv converted &quot;$1&quot;\' -- {} \\;\n</code></pre>\n<p>To perform these steps, a sub shell <code>sh</code> is used with <code>-exec</code>, running a one-liner with the <code>-c</code> flag, and passing the filename as the positional argument <code>&quot;$1&quot;</code> with <code>-- {}</code>. In between, the <code>utf-8</code> output file is temporarily named <code>converted</code>.</p>\n<p>Whereby <a href="https://linux.die.net/man/1/file" rel="noreferrer"><code>file -bi</code></a> means:</p>\n<ul>\n<li><p><code>-b</code>, <code>--brief</code>\nDo not prepend filenames to output lines (brief mode).</p>\n</li>\n<li><p><code>-i</code>, <code>--mime</code>\nCauses the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say for example <code>text/plain; charset=us-ascii</code> rather than <code>ASCII text</code>. The <code>sed</code> command cuts this to only <code>us-ascii</code> as is required by <code>iconv</code>.</p>\n</li>\n</ul>\n<p>The <code>find</code> command is very useful for such file management automation.\nClick here for <a href="http://hamwaves.com/find/en/index.html#list-the-character-encoding-of-textfiles" rel="noreferrer">more <code>find</code> galore</a>.</p>\n'}, {'answer_id': 40852057, 'author': 'Maciel Escudero Bombonato', 'author_id': 1096326, 'author_profile': 'https://Stackoverflow.com/users/1096326', 'pm_score': 1, 'selected': False, 'text': "<p>to write properties file (Java) normally I use this in linux (mint and ubuntu distributions):</p>\n\n<pre><code>$ native2ascii filename.properties\n</code></pre>\n\n<p>For example:</p>\n\n<pre><code>$ cat test.properties \nfirst=Execução número um\nsecond=Execução número dois\n\n$ native2ascii test.properties \nfirst=Execu\\u00e7\\u00e3o n\\u00famero um\nsecond=Execu\\u00e7\\u00e3o n\\u00famero dois\n</code></pre>\n\n<p>PS: I writed Execution number one/two in portugues to force special characters.</p>\n\n<p>In my case, in first execution I received this message:</p>\n\n<pre><code>$ native2ascii teste.txt \nThe program 'native2ascii' can be found in the following packages:\n * gcj-5-jdk\n * openjdk-8-jdk-headless\n * gcj-4.8-jdk\n * gcj-4.9-jdk\nTry: sudo apt install &lt;selected package&gt;\n</code></pre>\n\n<p>When I installed the first option (gcj-5-jdk) the problem was finished.</p>\n\n<p>I hope this help someone.</p>\n"}, {'answer_id': 44788426, 'author': 'lalthomas', 'author_id': 2182047, 'author_profile': 'https://Stackoverflow.com/users/2182047', 'pm_score': 2, 'selected': False, 'text': '<p>DOS/Windows: use <a href="https://en.wikipedia.org/wiki/Code_page" rel="nofollow noreferrer">Code page</a></p>\n\n<pre><code>chcp 65001&gt;NUL\ntype ascii.txt &gt; unicode.txt\n</code></pre>\n\n<p>Command <code>chcp</code> can be used to change the code page. Code page 65001 is Microsoft name for UTF-8. After setting code page, the output generated by following commands will be of code page set.</p>\n'}, {'answer_id': 51036143, 'author': 'Dorian', 'author_id': 407213, 'author_profile': 'https://Stackoverflow.com/users/407213', 'pm_score': 1, 'selected': False, 'text': '<p>With ruby:</p>\n\n<pre><code>ruby -e "File.write(\'output.txt\', File.read(\'input.txt\').encode(\'UTF-8\', \'binary\', invalid: :replace, undef: :replace, replace: \'\'))"\n</code></pre>\n\n<p>Source: <a href="https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences" rel="nofollow noreferrer">https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences</a></p>\n'}, {'answer_id': 51122390, 'author': 'kinORnirvana', 'author_id': 2260864, 'author_profile': 'https://Stackoverflow.com/users/2260864', 'pm_score': 0, 'selected': False, 'text': '<p>Use this Python script: <a href="https://github.com/goerz/convert_encoding.py" rel="nofollow noreferrer">https://github.com/goerz/convert_encoding.py</a>\nWorks on any platform. Requires Python 2.7.</p>\n'}, {'answer_id': 52366373, 'author': 'yota', 'author_id': 495769, 'author_profile': 'https://Stackoverflow.com/users/495769', 'pm_score': 0, 'selected': False, 'text': '<p>My favorite tool for this is Jedit (a java based text editor) which has two very convenient features :</p>\n\n<ul>\n<li>One which enables the user to reload a text with a different encoding (and, as such, to control visually the result)</li>\n<li>Another one which enables the user to explicitly choose the encoding (and end of line char) before saving</li>\n</ul>\n'}, {'answer_id': 52725747, 'author': 'Nikolai Varankine', 'author_id': 1451029, 'author_profile': 'https://Stackoverflow.com/users/1451029', 'pm_score': 1, 'selected': False, 'text': '<p>Simply change encoding of loaded file in IntelliJ IDEA IDE, on the right of status bar (bottom), where current charset is indicated. It prompts to Reload or Convert, use Convert. Make sure you backed up original file in advance.</p>\n'}, {'answer_id': 59119195, 'author': 'tiennou', 'author_id': 444323, 'author_profile': 'https://Stackoverflow.com/users/444323', 'pm_score': 0, 'selected': False, 'text': '<p>If macOS GUI applications are your bread and butter, <a href="https://subethaedit.net/" rel="nofollow noreferrer">SubEthaEdit</a> is the text editor I usually go to for encoding-wrangling — its "conversion preview" allows you to see all invalid characters in the output encoding, and fix/remove them.</p>\n\n<p>And it\'s <a href="https://github.com/subethaedit/SubEthaEdit" rel="nofollow noreferrer">open-source</a> now, so yay for them .</p>\n'}, {'answer_id': 62976460, 'author': 'Amr Ali', 'author_id': 4208440, 'author_profile': 'https://Stackoverflow.com/users/4208440', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Try EncodingChecker</strong></p>\n<p><a href="https://github.com/amrali-eg/EncodingChecker" rel="nofollow noreferrer">EncodingChecker on github</a></p>\n<p>File Encoding Checker is a GUI tool that allows you to validate the text encoding of one or more files. The tool can display the encoding for all selected files, or only the files that do not have the encodings you specify.</p>\n<p>File Encoding Checker requires .NET 4 or above to run.</p>\n<p>For encoding detection, File Encoding Checker uses the <a href="https://github.com/CharsetDetector/UTF-unknown" rel="nofollow noreferrer">UtfUnknown</a> Charset Detector library. UTF-16 text files without byte-order-mark (BOM) can be detected by heuristics.</p>\n<p><a href="https://i.stack.imgur.com/q1i52.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q1i52.png" alt="enter image description here" /></a></p>\n'}, {'answer_id': 63176205, 'author': 'Amr Ali', 'author_id': 4208440, 'author_profile': 'https://Stackoverflow.com/users/4208440', 'pm_score': 1, 'selected': False, 'text': '<p>In powershell:</p>\n<pre><code>function Recode($InCharset, $InFile, $OutCharset, $OutFile)  {\n    # Read input file in the source encoding\n    $Encoding = [System.Text.Encoding]::GetEncoding($InCharset)\n    $Text = [System.IO.File]::ReadAllText($InFile, $Encoding)\n    \n    # Write output file in the destination encoding\n    $Encoding = [System.Text.Encoding]::GetEncoding($OutCharset)    \n    [System.IO.File]::WriteAllText($OutFile, $Text, $Encoding)\n}\n\nRecode Windows-1252 &quot;$pwd\\in.txt&quot; utf8 &quot;$pwd\\out.txt&quot; \n</code></pre>\n<p>For a list of supported encoding names:</p>\n<p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding</a></p>\n'}, {'answer_id': 63465837, 'author': 'Pavel Morshenyuk', 'author_id': 112936, 'author_profile': 'https://Stackoverflow.com/users/112936', 'pm_score': 1, 'selected': False, 'text': '<p>There is also a web tool to convert file encoding: <a href="https://webtool.cloud/change-file-encoding" rel="nofollow noreferrer">https://webtool.cloud/change-file-encoding</a></p>\n<p>It supports wide range of encodings, including some rare ones, like IBM code page 37.</p>\n'}, {'answer_id': 64214053, 'author': 'Marcelo Teixeira Ruggeri', 'author_id': 2368184, 'author_profile': 'https://Stackoverflow.com/users/2368184', 'pm_score': 3, 'selected': False, 'text': "<p>Assuming, you don't know the input encoding and still wish to automate most of the conversion, I concluded this <strong>one liner</strong> from summing up previous answers.</p>\n<pre><code>iconv -f $(chardetect input.text | awk '{print $2}') -t utf-8 -o output.text\n</code></pre>\n"}, {'answer_id': 71692418, 'author': 'Alex Czarto', 'author_id': 67006, 'author_profile': 'https://Stackoverflow.com/users/67006', 'pm_score': 0, 'selected': False, 'text': '<h2>Visual Studio Code</h2>\n<ol>\n<li><strong>Open your file</strong> in <a href="https://code.visualstudio.com" rel="nofollow noreferrer">Visual Studio Code</a></li>\n<li><strong>Reopen with Encoding</strong>: In the bottom status bar, to the right, you should see your current file encoding (eg &quot;UTF-8&quot;). Click this and select &quot;Reopen with Encoding&quot;.</li>\n<li><strong>Select the correct encoding</strong> of the file (eg: ISO 8859-2).</li>\n<li><strong>Confirm</strong> that your content is displaying as expected.</li>\n<li><strong>Save with Encoding</strong>: The bottom status bar should now display your new encoding format (eg: ISO 8859-2). Click this and choose &quot;Save with Encoding&quot; and select UTF-8 (or whatever new encoding you want).</li>\n</ol>\n<p><strong>NOTE: THIS WILL OVERWRITE YOUR ORGINIAL FILE. MAKE A BACKUP FIRST.</strong></p>\n'}]
['https://Stackoverflow.com/questions/64860', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2948/']