How to read a file in UTF-8 and remove a BOM in batch script?
Posted: 04 Oct 2021 07:11
Hi
How to read a file in UTF-8 and remove a BOM in batch script?
How to read a file in UTF-8 and remove a BOM in batch script?
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
@echo off
set "rmvBomRedir=|((pause&pause&pause)>nul&findstr "^^")"
set "rmvBomFor=^|((pause^&pause^&pause^)^>nul^&findstr "^^"^)"
>nul chcp 65001
:: redirect to console
type "utf8.txt" %rmvBomRedir%
:: redirect to a pipe
(type "utf8.txt" %rmvBomRedir%)|find /v ""
:: redirect to a file
>"utf8noBom.txt" (type "utf8.txt" %rmvBomRedir%)
:: process in a FOR /F loop
for /f "delims=" %%i in ('type "utf8.txt" %rmvBomFor%') do echo %%i
pause