batch file - need to remove the trailing :

May 20, 2009 at 09:34:10
Specs: Windows Vista
Here is what I have:

@ECHO OFF
FOR /F "tokens=3" %%A IN ('PING www.google.com -n 1 ^| find "Reply from"') DO SET output=%%A
echo %output%

The output that I get is an IP address with the : at the end - e.g., 216.239.61.104:

I need the IP address without the : at the end, e.g., 216.239.61.104

Any help will be much appreciated.
Thanks.
GM


See More: batch file - need to remove the trailing :

Report •


#1
May 20, 2009 at 10:43:44
use "tokens=3 delims= :" inside for loop

or

echo %output:~,-1%


Report •

#2
May 20, 2009 at 10:46:35
FOR /F "tokens=3" %%A IN ('PING www.google.com -n 1 ^| find "Reply from"') DO SET output=%%A
set output=%output:~0,-1%
echo %output%


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
May 20, 2009 at 19:45:11
Fantastic. Thank you very much.

GM


Report •

Related Solutions

#4
May 20, 2009 at 20:22:49
Could you please help me with one more thing...

I have a txt file with the following content:

=================
Starting EC2 instance i-8xxx3e8... Started

Your server is now available at hhttp://ec2-10-10-10-10.compute-1.amazonaws.com
=================

I want my batch file to find the line that starts with "Your server is now available" and extract the "ec2-10-10-10-10.compute-1.amazonaws.com" (hostname without the http bit) and then use this in the above batch script (PING ec2-10-10-10-10.compute-1.amazonaws.com) in order to get the IP address.

Thank you again for your help.

GM


Report •

#5
May 21, 2009 at 00:34:39
Assuming that hhttp is a typo and really should be:

http

==================================
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=7 delims= " %%a in ('find "Your server" ^< server.txt') do (
set site=%%a
set site=!site:http://=!
echo !site!
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question