我无法从CSV文件中选择特定列。我只需要选择2列:
1002 2019-02-01 00:03:07
这是我的例子:
(Get-Content c:Usersfile.csv) -replace ',', "`t" -replace '/', '-' |
foreach { $_ + "`t 1 `t 255 `t 1 `t 0" } |
Select -Skip 1 |
Set-Content C:Usersoutfile.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
PowerShell有一个内置的Import-Csv
命令。这样就无需自己手动解析 CSV 文件。你可以做这样的事情:
Import-Csv -Path c:Usersfile.csv | Select-Object -Property Column1, Column2