我将尝试使用 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
这里可以看到输入和输出的一部分:
我如何强制输出文件为ascii而不是某种unicode类型?
*** 编辑:进一步研究发现输入文件实际上是windows-1252编码,Get-Content似乎无法本地处理(?)