我试图返回我在txt文件上执行的搜索的第二行结果。 的数据是在Powershell:返回仅搜索的第二行
Readings : \\Server1\memory\available mbytes :
2107
格式我想只得到2107。 这是我到目前为止有:
$file = "D:\PerfTest.txt" # import data
$data = gc $file
$RAM = $Data | Select-String -Pattern "available mbytes :" | ForEach-Object -Context 1
,但它给了我下面的:
Readings : \\Server1\memory\available mbytes :
2107
但我只想得到这个数字。请帮忙吗?
感谢
我想补充到上述情况,如果我用
$RAM = $Data | Select-String -Pattern "available mbytes :" -Context 1 | Foreach {if ($_ -match '(\d+)$') {$matches[1]}}
返回整数和小数不。所以用一个小数点什么出来78125,而不是0.78125
'$数据| Select-String -Pattern“available mbytes:”-Context 1 | ForEach-Object {$ _.Context.PostContext [0] .Trim()}' – PetSerAl
这工作完全谢谢 – mattnicola