English 中文(简体)
组合 CSV 文件电壳
原标题:Combing CSV files powershell

下面是背后的故事, 我试图以几种不同的方式验证数据。 我询问过一个数据库, 并将这些数据导出到 csv 中 。

然后用电壳,我执行以下命令

$staleDates = Import-Csv DataAudit.csv | Where-Object { $_.asOfDate -ne "" } | Foreach-Object { $_.AsOfDate = $_.AsOfDate -as [datetime]; $_ } | Where-Object {$_.asOfDate -lt $measuredDate}

$nullDates = Import-Csv DataAudit.csv | Where-Object {$_.asOfDate -eq ""}

$percentTooLarge = Import-Csv DataAudit.csv | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object { $_.SumHoldingPercent -gt 100 }

$percentTooSmall = Import-Csv DataAudit.csv | Where-Object {$_.SumHoldingPercent -ne "" } | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object {$_.SumHoldingPercent -lt 99.99999 }

我能否将这4个变数的结果 合并成一个CSV 来发邮件作为坏数据报告?

还有,我用的是Powershell v1.0(Powershell v1.0)

最佳回答

下列工作应当有效:

$badData = Import-Csv DataAudit.csv | Where-Object { $_.asOfDate -ne "" } | Foreach-Object { $_.AsOfDate = $_.AsOfDate -as [datetime]; $_ } | Where-Object {$_.asOfDate -lt $measuredDate}
$badData += Import-Csv DataAudit.csv | Where-Object {$_.asOfDate -eq ""}
$badData += Import-Csv DataAudit.csv | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object { $_.SumHoldingPercent -gt 100 }
$badData += Import-Csv DataAudit.csv | Where-Object {$_.SumHoldingPercent -ne "" } | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object {$_.SumHoldingPercent -lt 99.99999 }

$badData | Export-CSV -NoTypeInformation -Path allBadData.csv
问题回答

暂无回答




相关问题
Styling rows in table that uses CSV data through PHP

I ve been working on this simple code that puts a CSV file into a nice table. But because the data is imported, styling ODD rows is a pretty hard thing to do. All I need would be a method to address ...

PHP - Sanitise a comma separated string

What would be the most efficient way to clean a user input that is a comma separated string made entirely on numbers - e.g 2,40,23,11,55 I use this function on a lot of my inputs function clean($...

marking duplicates in a csv file

I m stumped with a problem illustrated in the sample below: "ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, ...

Interactive heat map in Flex

I’m at a very basic level with Flex and with programming in general. I am working on a project where I have data in an Excel (.csv) format, it’s a large Excel plot/matrix where each cell has a ...

热门标签