获取内容| Select-String返回结果集中的仅顶部行

时间:2018-08-18 15:44:31

标签: powershell

仅从以下命令获取顶部行:

$G = Get-Content $SourceFile | select-string -pattern $SearchKeyword2`** 

上面的命令返回它在文档中找到的多个行号,我们要选择返回的前1个..。我们如何才能对此应用过滤器,以便仅返回第一行。就像我们在SQL Server中所做的那样

1 个答案:

答案 0 :(得分:2)

使用Select-Object -First 1

$G = Get-Content $SourceFile | Select-String -Pattern $SearchKeyword2 | Select-Object -First 1