I want to concatenate multiple text files, that are encoded as UTF8+BOM, using a Windows 10 batch file. In between each file, I want to add a blank line. I used the TYPE command as shown below, but I found that since each file has a UTF-8 BOM on it, the resulting output file has BOMs in in the middle of it. I also tried the COPY command and it did the same thing.
Example 1
ECHO -- File start >OUTPUT.TXT
TYPE file1 >>OUTPUT.TXT
ECHO( >>OUTPUT.TXT
TYPE file2 >>OUTPUT.TXT
ECHO( >>OUTPUT.TXT
.
.
.
Example 2
COPY header+file1+blankline+file2+blankline+... OUTPUT.TXT
I expected that TYPE would not echo the literal characters, but would instead use the BOM to determine the file encoding so that it could display the file correctly. Apparently not. :-( Does the TYPE command not understand Unicode at all? If it was a UTF-16 file would it really output nul characters between?
What is an alternative? Do I need to use PowerShell?
chcp 65001
as that's UTF-8 without BOM. Then you could try copy and see how that goes.