【发布时间】:2019-12-09 22:26:41
【问题描述】:
我正在尝试使用 Powershell 规范化一组制表符分隔的日志文件。
这是当前脚本:
(Get-ChildItem *.csv) |%{
#Store the name of the file & date
$Name = $_.basename
$FileDate = $_.CreationTime
#Prepends the following to each message: unique Identifer, Hostname, date
(Get-Content $_.fullname) -replace "^","AR-LOG|$Name|$FileDate|"|
#Replaces the TAB delimeter with a Pipe delimeter
Foreach-Object {$_ -replace ' ','|'} |
#Appends the resulting message in ascii
Out-File -append -FilePath normalized.log -Encoding ascii
输入和输出的sn-p可以在这里看到:
如何强制输出文件为 ascii 而不是某种类型的 unicode?p>
***编辑:进一步的故障排除显示输入文件实际上是 windows-1252 编码的,显然 Get-Content 无法本地处理(?)
【问题讨论】:
标签: powershell character-encoding