【问题标题】:How to pull data from specific column from imported CSV如何从导入的 CSV 中提取特定列的数据
【发布时间】:2014-11-05 05:35:08
【问题描述】:

我有这个 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 列中的数据提取到变量中?

【问题讨论】:

    标签: powershell csv


    【解决方案1】:

    该 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
    

    【讨论】:

    • 如果 CSV 使用非默认分隔符(例如制表符),则指定实际分隔符 (-Delimiter)。
    猜你喜欢
    • 2021-11-21
    • 2020-08-28
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多