Computing.Net > Forums > Programming > batch file - need to remove the trailing :

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch file - need to remove the trailing :

Reply to Message Icon

Name: gm22
Date: May 20, 2009 at 09:34:10 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: May 20, 2009 at 10:43:44 Pacific
Reply:

use "tokens=3 delims= :" inside for loop

or

echo %output:~,-1%


0

Response Number 2
Name: Mechanix2Go
Date: May 20, 2009 at 10:46:35 Pacific
Reply:

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


0

Response Number 3
Name: gm22
Date: May 20, 2009 at 19:45:11 Pacific
Reply:

Fantastic. Thank you very much.

GM


0

Response Number 4
Name: gm22
Date: May 20, 2009 at 20:22:49 Pacific
Reply:

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


0

Response Number 5
Name: Mechanix2Go
Date: May 21, 2009 at 00:34:39 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch file - need to remove the trailing :

DOS batch file need to rec pings www.computing.net/answers/programming/dos-batch-file-need-to-rec-pings/14727.html

Batch file: Adding to file names www.computing.net/answers/programming/batch-file-adding-to-file-names/9098.html

Batch File to remove files www.computing.net/answers/programming/batch-file-to-remove-files-/16226.html