根据.CSV中的行数据提取列

时间:2017-11-22 20:52:02

标签: powershell csv

使用PowerShell的Total Newbie,但过去常常使用带有.vbs的WSH - 所以希望能够正确地构建这个问题。

我想从.csv文件中提取x个列,仅当行数据等于某个值时 - 然后将过滤后的数据发送到另一个目标中的新.csv。

因此,以保存的Windows事件日志为例,我想提取列A-F,但仅限于列' A'等于错误' - 然后将该输出发送到子目录中的新.csv。

我认为我非常接近,但只能保存列A-F,但没有包含我需要的数据的行!

任何人都可以帮我解决这个问题,或者告诉我哪里出错了吗?

$folderPath = 'C:\DLA\'
$folderPathDest = 'C:\DLA\OUT\'
$desiredColumns = 'A','B','C','D','E','F'
$topics.Where({$desiredColumns.play -eq 'Error'}).topic

Get-ChildItem $folderPath -Name |
    ForEach-Object { 
        $filePath = $folderPath + $_
        $filePathdest = $folderPathDest + $_
        Import-Csv $filePath | Select $desiredColumns | Select $topics |
        Export-Csv -Path $filePathDest –NoTypeInformation
    }

1 个答案:

答案 0 :(得分:0)

只需将过滤器直接放入您的管道中:

Import-Csv $filePath | Select $desiredColumns | where {$_.A -eq 'Error'} | Export-Csv -Path $filePathDest –NoTypeInformation
相关问题