如何从导入的CSV
问题描述:
我有这个CSV文件中提取自特定列中的数据:如何从导入的CSV
Time of Day Process Name PID Operation Path Result
52:24.3 notepad.exe 4828 Process Start SUCCESS
52:24.3 notepad.exe 4828 Thread Create SUCCESS
52:24.3 notepad.exe 4828 Load Image C:\Windows\System32\notepad.exe SUCCESS
我导入文件到一个变量:
$csvContent = Import-CSV D:\Logfile.CSV
我试着拔出从数据列 “PID”:
$csvContent[0] | select PID
,但没有奏效。
如何将PID列中的数据拉出变量?
答
该CSV文件中没有逗号,它将所有标题导入为单个标题的标题。
您需要为文件中的元素指定分隔符。
例如:
Time of Day,Process Name,PID,Operation,Path,Result
52:24.3,notepad.exe,4828,Process Start,,SUCCESS
52:24.3,notepad.exe,4828,Thread Create,,SUCCESS
52:24.3,notepad.exe,4828,Load Image,C:\Windows\System32\notepad.exe,SUCCESS
要么,或指定实际的分隔符('-Delimiter')如果CSV使用非默认的分隔符(标签为实例)。 – 2014-11-04 21:46:11