Page 1 of 1

Parse For /F

Posted: 20 Nov 2009 12:23
by tom4tp
Please help.
I have a statement as :
for /f "tokens=3,* delims=:. " %%a in ('"ipconfig|find "IP Address""') do set ip=%%b

This will gives me all the IP Address of the system. I would like to eliminate ONLY the first local Active IPAddress, and ignore the rest. Appreciated any help.

Posted: 21 Nov 2009 16:29
by DosItHelp
tom4tp,

you could try the (new) :getIPConfig function. It returns an array of all ipconfig output, from there you can access what you need.
@echo off
call:getIPConfig arr
echo.%arr[1].IPAddress%
echo.%arr[2].IPAddress%
echo.%arr[3].IPAddress%
goto:eof

rem copy :getIPConfig function from http://www.dostips.com/DtCodeCmdLib.php#Function.getIPConfig

DosItHelp?

Posted: 23 Nov 2009 11:48
by avery_larry
You can use a goto statement to effectively break out of (most) for loops:

Code: Select all

for /f "tokens=3,* delims=:. " %%a in ('"ipconfig|find "IP Address""') do set ip=%%b && goto :continue
:continue
echo other stuff

So this code will only execute the set command once, and then it'll exit the for loop and continue on.

Posted: 24 Nov 2009 00:22
by tom4tp
Thanks Larry and DosItHelp,
Both method are working well, and saving my times a lot. Really appreciated you guys responded.

Thanks.

Tom P.