我无法从CSV文件中选择特定的列。我只需要选择2列:
1002 2019-02-01 00:03:07
这是我的例子:
(Get-Content c:\Users\file.csv) -replace ',', "`t" -replace '/', '-' |
foreach { $_ + "`t 1 `t 255 `t 1 `t 0" } |
Select -Skip 1 |
Set-Content C:\Users\outfile.csv
我现在的输出:
1002 Hafiz New Organization 9-6-2019 13:57 Check In 'Main1_Door1_Entrance Card Reader1 Main1_Door1_Entrance Card Reader1 1 255 1 0
1002 Hafiz New Organization 9-6-2019 15:44 Check In 'Main1_Door1_Entrance Card Reader1 Main1_Door1_Entrance Card Reader1 1 255 1 0
最终结果:
3006 2019-02-01 00:03:07 1 255 1 0
1005 2019-02-01 06:44:31 1 255 1 0
答案 0 :(得分:1)
PowerShell具有内置的Import-Csv
命令。这避免了您自己手动解析CSV文件的需要。您可以执行以下操作:
Import-Csv -Path c:\Users\file.csv | Select-Object -Property Column1, Column2