Problems w/ find/replace w/in FOR /F loop

December 30, 2010 at 09:31:46
Specs: Windows 7
Need to grab all IP's from PC using this:
FOR /F "tokens=2 delims=:" %%a in ('IPCONFIG /all ^|FIND "IP" ^|FIND "10."') do echo %%a

This is working but in Windows 7 the echo includes the words (Preferred)..not in XP
I would like to remove those words and just display the IP's.

Tried replacing..and this works but now does not give me both IP's for a PC that's connected via both wireless and LAN.

FOR /F "tokens=2 delims=:" %%a in ('IPCONFIG /all ^|FIND "IP" ^|FIND "10."') DO SET IPADR=%%a
SET _NEWIPADR=%IPADR:(Preferred)=%
ECHO %_NEWIPADR%^

Do I need to add the replace inside the loop..if so, how?

Thx.


See More: Problems w/ find/replace w/in FOR /F loop

Report •


#1
December 30, 2010 at 10:10:16
setlocal EnableDelayedExpansion
FOR /F "tokens=2 delims=:" %%a in ('IPCONFIG /all ^|FIND "IP" ^|FIND "10."') DO (
  SET IPADR=%%a
  SET _NEWIPADR=!IPADR:(Preferred)=!
  ECHO !_NEWIPADR!
)

This issue was explained almost one billion times. Type SET /? to know more.


Report •

#2
January 3, 2011 at 09:03:28
The problem is if there are multiple IP's...only one is showing up.

Report •

Related Solutions


Ask Question