Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a txt file containing one line of text which looks something like this : " JDOE <03> UNIQUE 10.123.10.247 362" - only without then inverted commas. The various pieces of text can vary, but will always follow the same format. I want to extract the IP address to a variable in a batch file - any ideas on how I can do it? Is this possible?? thanks!

Hi Deirdre,
There must be a way in XP with the cmd extensions, tokens and all that. But it's beyond me.
Here's what I've got. It uses two small utilities, CHANGE & PREFIX.
####
@echo off > quit.bat
@echo echo %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >> quit.batecho.
echo This is the world famous %0.bat
echo.
echo copyright 2004 ThaiGuides.com All rights reserved
echo.
echo Free for private use. Others email: Consult@ThaiGuides.com
echo.
echo built and tested on windoze 2000; may act funny on other versions
echo.
echo. Purpose - get ip from file into var::*********************************************************************
if %1'==' quit which file?
change %1 32 13,10
echo.
echo.
find "." < %1 > ##
prefix "set MYvar=" <##> IPset.bat
call IPsetecho MYvar=%MYvar%
###Note: It wraps around in this little forum editor window, but I think you can figure it out.

Thanks, Mechanix, gives me another avenue to explore.. Dos is new to me, I'm afraid, I'm more used to unix and I wasn't very good at shell programming in that either! ;)

Hi
This might help if IP address the same
number of characters.@echo on
rem set IP var to file contents
set /p IP=<IP.txt
rem Get Last (Rightmost) 17 characters
set IPAdr=%IP:~-17%
echo %IPAdr%

If you are used to Unix and are going to be doing a lot of this type of thing, it might be worth downloading 'cygwin'. It is a shell that let's you run unix commands on windows PCs.
I use it all of the time on my windows boxes.
Just google for it. IT will be easy to find.

![]() |
Working with rs232 in Vis...
|
batch files
|

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