Cut the last 2 characters of cmd.exe script response
I want to write a script that esentially pings another computer and gets average as number only. Right now I have a script that gets average ping as needed and shows it, but it has 'ms' prefix and I want to get rid of it. I can't seem to find cut equivalent (alright, I did found, but I can't make my existing script and it work together) that is already in Windows (it should be in cmd.exe by default).
FOR /F "usebackq skip=11 tokens=6 delims== " %i IN (`ping host2.internal`) DO @echo %i
I get: 197ms, but I need it to look like: 197.
Replace the DO part with
DO @set FOO=%i & echo %FOO:~0,-3%
This assigns the value of %i to a temporary variable FOO so that you can then use the substring extraction capability of the shell (SET /? for explanation). I am shaving off three characters instead of two because %i includes a trailing space.
This works here in Win 8: the -4 is required for occasions where IPV6 is also in force.
FOR /F "tokens=5 delims==<ms" %i IN ('ping -4 www.google.com ^|find "Reply from"') DO @echo %i