Text File Encoding ANSI to UTF-8
Moderator: DosItHelp
Text File Encoding ANSI to UTF-8
How to change the Text File Encoding?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Text File Encoding ANSI to UTF-8
The easiest way (short of opening the file with a text editor and saving it manually) is probably with ConvertCP.exe. Beyond that, my next thought would be to add the UTF-8 BOM to the front of the text file, but that might not be the best solution for some circumstances.
Re: Text File Encoding ANSI to UTF-8
I agree, aGerman's ConvertCP.exe utility would be an ideal solution. You want to translate to code page 65001. Add the /B option if you want a BOM in your output.
Alternatively, you could use my JREPL.BAT utility. It is designed to do regular expression find/replace operations on text files, but it has the ability to read and write different encodings.
The following assumes the "ANSI" source encoding matches the default encoding used by your machine:
The above will terminate every line with carriage return linefeed (\r\n), regardless how the source lines were terminated. If you want to preserve the original line terminators, then add the /M option.
By default the output will include the BOM. If you don't want a BOM, then use /O "output.txt|utf-8|nb".
If the ANSI encoding does not match your machines default, then you will have to specify the encoding within the /I option. For example, if your encoding is Central/Eastern European code page 1250, then
Alternatively, you could use my JREPL.BAT utility. It is designed to do regular expression find/replace operations on text files, but it has the ability to read and write different encodings.
The following assumes the "ANSI" source encoding matches the default encoding used by your machine:
Code: Select all
call jrepl "$^" "" /f "input.txt" /o "output.txt|utf-8"
By default the output will include the BOM. If you don't want a BOM, then use /O "output.txt|utf-8|nb".
If the ANSI encoding does not match your machines default, then you will have to specify the encoding within the /I option. For example, if your encoding is Central/Eastern European code page 1250, then
Code: Select all
call jrepl "$^" "" /f "input.txt|windows-1250" /o "output.txt|utf-8"