Question

I have a file saved as UCS-2 Little Endian I want to change the encoding so I ran the following code:

cat tmp.log -encoding UTF8 > new.log

The resulting file is still in UCS-2 Little Endian. Is this because the pipeline is always in that format? Is there an easy way to pipe this to a new file as UTF8?

Was it helpful?

Solution

As suggested here:

Get-Content tmp.log | Out-File -Encoding UTF8 new.log

OTHER TIPS

I would do it like this:

get-content tmp.log -encoding Unicode | set-content new.log -encoding UTF8

My understanding is that the -encoding option selects the encdoing that the file should be read or written in.

load content from xml file with encoding.

(Get-Content -Encoding UTF8 $fileName)

If you are reading an XML file, here's an even better way that adapts to the encoding of your XML file:

$xml = New-Object -Typename XML
$xml.load('foo.xml')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top