0
样本数据看起来像(由制表分)由制表拆分前两列:如何选择从文本文件没有头在PowerShell中
value1 value2 value3 value4
我用获取内容| format-table来获取数据,但不知道如何获得前两列(value1和value2),因为它们没有标题来执行select。
感谢,
样本数据看起来像(由制表分)由制表拆分前两列:如何选择从文本文件没有头在PowerShell中
value1 value2 value3 value4
我用获取内容| format-table来获取数据,但不知道如何获得前两列(value1和value2),因为它们没有标题来执行select。
感谢,
您可以使用Import-Csv
与-Header
参数来自己定义的标题:
Import-Csv .\values.txt -Delimiter "`t" -Header col1,col2,col3,col4 |Format-Table col1,col2
如果你想使用Get-Content
,你可以使用-split
操作:
Get-Content .\values.txt |ForEach-Object {
$col1,$col2,$null = $_ -split '\s+'
New-Object psobject -Property @{
Col1 = $col1
Col2 = $col2
}
}
\s+
是“1个或多个空格字符”的正则表达式