Parse For /F

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tom4tp
Posts: 2
Joined: 20 Nov 2009 12:17
Contact:

Parse For /F

#1 Post by tom4tp » 20 Nov 2009 12:23

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.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 21 Nov 2009 16:29

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?

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#3 Post by avery_larry » 23 Nov 2009 11:48

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.

tom4tp
Posts: 2
Joined: 20 Nov 2009 12:17
Contact:

#4 Post by tom4tp » 24 Nov 2009 00:22

Thanks Larry and DosItHelp,
Both method are working well, and saving my times a lot. Really appreciated you guys responded.

Thanks.

Tom P.

Post Reply