How to read the particular value from Ping result

回眸只為那壹抹淺笑 提交于 2019-12-08 08:59:17

问题


I am trying to read values from below ping results, like I want to read Received value as 4 or Lost value as 0 using regular expression.

Ping statistics for 74.125.200.94:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 63ms, Maximum = 64ms, Average = 63ms

I am trying with below but no go, Any help?

$test = ping google.co.in
$test -match "^Average = \((\d+)\)$"

回答1:


Just use [regex]::Match to grab the information:

$test = ping google.co.in

$match = [regex]::Match($test, 'Received = (\d+), Lost = (\d+)')
$received = $match.Groups[1].Value
$lost = $match.Groups[2].Value


来源:https://stackoverflow.com/questions/39506287/how-to-read-the-particular-value-from-ping-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!