【发布时间】:2021-10-05 16:02:54
【问题描述】:
使用 Powershell 删除多个 CSV 文件中的空行。这是我为每个循环尝试的代码。但它正在写空文件。生成的文件应该以正确的格式在 excel 和 notepad++ 中打开。
Get-ChildItem $paramDest -Filter *Test*.csv | ForEach-Object {
$content = Get-Content $_.FullName | Where { $_.Replace("","","").trim() -ne "" }
Out-File -InputObject $content -FilePath $_.FullName
}
我还有一些其他文件集,代码应该适用于这两种文件。我可以为这 2 个单独的文件设置 2 个单独的代码。
这里是另一种文件示例格式
【问题讨论】:
-
where { $_.Replace('","','').trim('"') -ne '' }
标签: powershell powershell-2.0 powershell-3.0