简体   繁体   中英

How to read the particular value from Ping result

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+)\)$"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM