如何用批处理文件读取一个文本的最后一个数字
如何用批处理文件读取一个文本的最后一串数字?文本内容如下:Pinging192.168.100.100with32bytesofdata:Replyfrom192.168...
如何用批处理文件读取一个文本的最后一串数字?文本内容如下:
Pinging 192.168.100.100 with 32 bytes of data:
Reply from 192.168.100.100: bytes=32 time=29ms TTL=243
Reply from 192.168.100.100: bytes=32 time=26ms TTL=243
Reply from 192.168.100.100: bytes=32 time=26ms TTL=243
Reply from 192.168.100.100: bytes=32 time=27ms TTL=243
Ping statistics for 192.168.100.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 26ms, Maximum = 29ms, Average = 27ms
希望读取的字符串是“ Average = ”后面的“27”。谢谢!
注意,如果ms数是三位数或者4位数,仍然需要能够完整读取出来 展开
Pinging 192.168.100.100 with 32 bytes of data:
Reply from 192.168.100.100: bytes=32 time=29ms TTL=243
Reply from 192.168.100.100: bytes=32 time=26ms TTL=243
Reply from 192.168.100.100: bytes=32 time=26ms TTL=243
Reply from 192.168.100.100: bytes=32 time=27ms TTL=243
Ping statistics for 192.168.100.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 26ms, Maximum = 29ms, Average = 27ms
希望读取的字符串是“ Average = ”后面的“27”。谢谢!
注意,如果ms数是三位数或者4位数,仍然需要能够完整读取出来 展开
1个回答
展开全部
可以不使用文本 直接从命令中获取:
@echo off& for /f "tokens=8 delims==ms, " %%1 in ('ping 192.168.100.100^| findstr "Average"')do echo %%1
pause 1>nul
如果想用文本的话:
@echo off
for /f "tokens=8 delims==ms, " %%1 in ('findstr "Average" 1.txt')do echo %%1& pause 1>nul
@echo off& for /f "tokens=8 delims==ms, " %%1 in ('ping 192.168.100.100^| findstr "Average"')do echo %%1
pause 1>nul
如果想用文本的话:
@echo off
for /f "tokens=8 delims==ms, " %%1 in ('findstr "Average" 1.txt')do echo %%1& pause 1>nul
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询