当A列的值(即CSV
)等于B列的值(即DevID
)
ProdID
文件的整行
我的代码:
$MergedFile= Import-Csv "C:\Users\d-mansings\Desktop\Mergedata.csv"
$MergeTable=@{}
foreach($line in $MergedFile){
if(Compare-Object $line.DevID $line.ProdID){
echo "Not Matched, Keep the file as it"}
else{ echo "Row need to be deleted"}
}
代替Row need to be deleted
我需要一个删除整行的命令。
以下是我的CSV
文件:
"DevID","ProdID","cfname"
"-----","-----","------"
"10201","10202","Risk ID"
"10202","20202","Issue ID"
"10203","20203","Dependency ID"
"10204","20204","Server ID"
"10205","20205","Parent Application ID"
"10206","20206","Application Service ID"
"10207","20207","Application Supportability"
"10208","20208","Application Compatibility"
"10300","20300","Application Status"
"10301","20302","Contact ID Type 2"
"10302","20302","Contact ID Type 3"
"10303","20303","Contact ID Type 4"
"10304","10304","Business Service Manager"
"10308","20308","Server Location Name:"
答案 0 :(得分:0)
您可以使用Where-Object
cmdlet过滤DevID
不等于ProdID
的所有条目,并将结果通过管道传输到Export-Csv
cmdlet以保存csv:
Import-Csv 'source.csv' |
Where { $_.DevID -ne $_.ProdID } |
Export-Csv -Path 'destination.csv' -NoTypeInformation
<强>输出:强>
"DevID","ProdID","cfname"
"10201","10202","Risk ID"
"10202","20202","Issue ID"
"10203","20203","Dependency ID"
"10204","20204","Server ID"
"10205","20205","Parent Application ID"
"10206","20206","Application Service ID"
"10207","20207","Application Supportability"
"10208","20208","Application Compatibility"
"10300","20300","Application Status"
"10301","20302","Contact ID Type 2"
"10302","20302","Contact ID Type 3"
"10303","20303","Contact ID Type 4"
"10308","20308","Server Location Name:"