如何从Ping结果读取特定值 [英] How to read the particular value from Ping result

查看:105
本文介绍了如何从Ping结果读取特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从以下ping结果中读取值,例如我想使用正则表达式将Received值读取为4或Lost值读取为0.

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

推荐答案

只需使用[regex]::Match即可获取信息:

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

这篇关于如何从Ping结果读取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆