我一直在尝试在Powershell中导入CSV,然后仅导出特定的第2、3和5列,并忽略最后一行。
TestFile.csv
:
"1","2","3","4","5" "1","2","3","4","5" "1","2","3","4","5" "1","2","3","4","5" "1","2","3","4","5" ,,,2,2,2,,,2,,
使用的PowerShell脚本:
Import-Csv '\\DESKTOP-QC1GB24\Allpay DD\Processing\TestFile.csv' -Header (1..5|%{"Column$_"}) |
Select-Object Column2, Column3, Column5 -SkipLast 1 |
Export-Csv -Path "\\DESKTOP-QC1GB24\Allpay DD\Completed\New.CSV"
我得到的结果(new.csv
):
#TYPE Selected.System.Management.Automation.PSCustomObject "Column2","Column3","Column5" "2","3","5" "2","3","5" "2","3","5" "2","3","5" "2","3","5"
我面临的问题是它导出临时列标题和数据上方的一些文本。有没有办法排除这种情况?同样喜欢保留文件原始名称的id是否可以用原始文件名+ _new导出?