1
votes

Out of a bunch of files I want to concatenate all files whose filename starts with a 1 into a textfile named 1.txt. The encoding of the source files is UTF16-LE and this shall also be the encoding of the target file. But using my powershell script (code below) results in a UTF-8 file with defect special signs (Umlauts etc.)

This is my code:

Powershell.exe cat  Disc:\data\files\1\filename-1* > Path:\here\1.txt

I found several approaches using Get-Content and Out-File but was not able to adapt those commands to my wildcard needs. As far as I understand, cat is a standard alias of get-content, so I wonder why I cannot just replace cat with get-content. Additionally, get-content has a -Encoding CharSet parameter but changing my code like this:

Powershell.exe cat  Disc:\data\files\1\filename-1* > Path:\here\1.txt -encode Unicode

(which is the charset for UTF-16 format little-endian byte order) does not change a thing. Neither does BigEndianUnicode or UTF8.

Thanks for any help!

1

1 Answers

2
votes

You can't specify the encoding when using a redirection operator (>). Use the Out-File cmdlet instead:

Get-Content C:\path\to\input* | Out-File D:\path\to\output.txt -Encoding Unicode