3

I am using a loop and this command to display my ping result in a text file:

ping.exe -n 1 xxx.xxx.xxx.xxx>> trace.txt

The result is 8 lines of code!

Pinging xxxxx [xxx.xxx.xxx.xxx] with 32 bytes of data:

Reply from xxx.xxx.xxx.xxx: bytes=32 time<1ms TTL=125

Ping statistics for xxx.xxx.xxx.xxx:

Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

I just would like to display the last line as I don't want a huge text file as result.

The perfect result would be:

Ping 11oct2011 16h56 : Minimum = 0ms, Maximum = 0ms, Average = 0ms

2

sounds you would like tail.

ping test_server | tail -n 1

I got it with cygwin.

|improve this answer|||||
1

With just cmd.exe from Windows 7, the following command should be able to achieve your expected output:

for /f "delims=" %a in ('ping -n 1 INSERTIPHERE ^| find "Minimum"') do @echo %TIME% %DATE% %a >> ping.txt

The output would be:

18:22:24.45 11/10/2011 Minimum = 13ms, Maximum = 13ms, Average = 13ms

|improve this answer|||||
1

I like @bdecaf's answer, but prefer more useful output.

$ ping svcuat1.ec2 | sed '/PING/!d;N;s/\n/, /'
PING svcuat1.ec2 (172.31.16.60): 56 data bytes, 64 bytes from 172.31.16.60: icmp_seq=0 ttl=63 time=91.171 ms

What it does is:

  • "Not delete" (!d) the lines matching PING (meaning delete the rest)
  • Append the next line of input to the pattern space N
  • Swap the newline char with a comma and space s/\n/, /
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.