小编Ter*_*alo的帖子

在 Powershell 中选择 CSV 列,其中标题名称包含特定字符串

我有一个大约 10-15 列的数据文件,我想从中提取特定的列。有些列我知道确切的列标题,而其他列我只知道前两个字母将始终是“FC”。如何仅选择我知道列标题的列和以“FC”开头的列?从“FC”列开始,我尝试过这样的:

$myCSV = Import-CSV "mydata.txt" -Delimiter "`t"
$FCcols = $myCSV[0].psobject.Properties | foreach { $_.Name } | Where {$_ -match "FC"}
$myCSV | select $FCcols
Run Code Online (Sandbox Code Playgroud)

但我只是收到一个错误:

Select-Object : Cannot convert System.Management.Automation.PSObject to one of 
the following types {System.String, System.Management.Automation.ScriptBlock}.
At line:3 char:16
+ $myCSV | select <<<<  $FCcols
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupport 
   edException
    + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Co 
   mmands.SelectObjectCommand
Run Code Online (Sandbox Code Playgroud)

然后,如果我尝试:

$myCSV = Import-CSV "mydata.txt" -Delimiter "`t"
$FCcols = [System.Collections.ArrayList]@()
$myCSV[0].psobject.Properties | foreach { $_.Name } | Where …
Run Code Online (Sandbox Code Playgroud)

csv powershell

5
推荐指数
1
解决办法
8572
查看次数

标签 统计

csv ×1

powershell ×1