我编写了一个提取拼平均值的批处理代码,如下:- @echo off
- for /l %%p in (130,1,150) do @ping 172.16.3.%%p -n 1 -w 10 | find " " /i >>旧.txt
- (for /f "tokens=1,2,6 delims== " %%i in ('findstr /i "Pinging Average" 旧.txt') do if /i "%%i" == "Pinging" (set /p =%%j:<nul) else set /p =Average=%%k<nul&echo.)>>新.txt
- pause
复制代码 运行结果如下:- 旧.txt
-
- Pinging 172.16.3.130 with 32 bytes of data:
-
- Reply from 172.16.3.130: bytes=32 time=58ms TTL=64
-
- Ping statistics for 172.16.3.130:
-
- Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
-
- Approximate round trip times in milli-seconds:
-
- Minimum = 58ms, Maximum = 58ms, Average = 58ms
-
- Pinging 172.16.3.131 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.131:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.132 with 32 bytes of data:
-
- Reply from 172.16.3.132: bytes=32 time<1ms TTL=128
-
- Ping statistics for 172.16.3.132:
-
- Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
-
- Approximate round trip times in milli-seconds:
-
- Minimum = 0ms, Maximum = 0ms, Average = 0ms
-
- Pinging 172.16.3.133 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.133:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.134 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.134:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.135 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.135:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.136 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.136:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.137 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.137:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.138 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.138:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.139 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.139:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.140 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.140:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.141 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.141:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.142 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.142:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.143 with 32 bytes of data:
-
- Reply from 172.16.3.143: bytes=32 time=1ms TTL=128
-
- Ping statistics for 172.16.3.143:
-
- Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
-
- Approximate round trip times in milli-seconds:
-
- Minimum = 1ms, Maximum = 1ms, Average = 1ms
-
- Pinging 172.16.3.144 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.144:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.145 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.145:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.146 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.146:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.147 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.147:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.148 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.148:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.149 with 32 bytes of data:
-
- Request timed out.
-
- Ping statistics for 172.16.3.149:
-
- Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
-
- Pinging 172.16.3.150 with 32 bytes of data:
-
- Reply from 172.16.3.150: bytes=32 time=1ms TTL=128
-
- Ping statistics for 172.16.3.150:
-
- Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
-
- Approximate round trip times in milli-seconds:
-
- Minimum = 1ms, Maximum = 1ms, Average = 1ms
复制代码
- 新.txt
-
- 172.16.3.130:Average=58ms
-
- 172.16.3.131:172.16.3.132:Average=0ms
-
- 172.16.3.133:172.16.3.134:172.16.3.135:172.16.3.136:172.16.3.137:172.16.3.138:172.16.3.139:172.16.3.140:172.16.3.141:172.16.3.142:172.16.3.143:Average=1ms
-
- 172.16.3.144:172.16.3.145:172.16.3.146:172.16.3.147:172.16.3.148:172.16.3.149:172.16.3.150:Average=1ms
复制代码 现在我想要将 新.txt 中的显示内容修改为- 172.16.3.130:Average=58ms
- 172.16.3.131:
- 172.16.3.132:Average=0ms
- 172.16.3.133:
- 172.16.3.134:
- 172.16.3.135:
- 172.16.3.136:
- 172.16.3.137:
- 172.16.3.138:
- 172.16.3.139:
- 172.16.3.140:
- 172.16.3.141:
- 172.16.3.142:
- 172.16.3.143:Average=1ms
- 172.16.3.144:
- 172.16.3.145:
- 172.16.3.146:
- 172.16.3.147:
- 172.16.3.148:
- 172.16.3.149:
- 172.16.3.150:Average=1ms
复制代码 即每个IP后面跟一个平均值,而且一个IP一行,我应该如何修改代码?请各位前辈指教。
[ 本帖最后由 laotou1000 于 2009-10-9 11:16 编辑 ] |