A0Bluetooth
(1)
SetLocal
(1)
ECtn
(1)
EDti
(1)
Bluetooth
(1)
Povoleno
(1)
Vyhrazen
(1)
Hamachi
(1)

parsing interface list from netshell

Asked By Petr Laznovsky
18-Nov-09 05:42 PM
Hi there, I am beginner in the CMD scripting.

I want to get interface list, each iface into each variable. I have two
problems with this. My command is:

for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j

I am use local (Czech) language version of WXP and the tranlation of
nesth use two words for loopback ("zpetna smycka" something like "loop
back" with space between those two words). When I try to parse it, there
is problem with delimiter bacause there are two words for loopback in
the column "TYPE", something like this:


Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled                       Dedicated        dummy
Enabled                       Dedicated        Local Area Connection
Enabled                       Internal         Internal
Enabled                       Loop Back        Loop Back

Second probles is I have no idea how to push ecach line of output (name
of each iface) into separated variable.

Any ideas??

Petr Laznovsky

When I run the commandfor /f "tokens=3,* delims= " %i in ('netsh in sh in') do

Pegasus [MVP] replied to Petr Laznovsky
18-Nov-09 06:18 PM
When I run the command
for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j
then my console output looks radically different from yours, even when
allowing for linguistic differences. I am therefore unable to give you a
solution that is guaranteed to work for you. And while I appreciate that the
Czech translation of "loopback" generates two words, I do not understand
what you are trying to extract from the console output.

The code below is an example for your second question: How to assign each
line of the screen output to a variable. The text file d:\temp\test.txt
contains the exact console lines that you posted in your note.

@echo off
SetLocal EnableDelayedExpansion
set Line=0
for /F "delims=" %%a in ('type "d:\temp\test.txt"') do (
set /a Line=!Line! + 1
set Var=%%a
echo Line!Line!=!Var!
)

This is a multi-part message in MIME format.

Petr Laznovsky replied to Pegasus [MVP]
19-Nov-09 06:43 AM
This is a multi-part message in MIME format.
--------------050401090701060604040105
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 8bit

Pegasus [MVP] napsal(a):

The output I post is not output from full parsing command, but from
words for loopback" problem. Real outpul from "netsh in sh in" is following:

Admin. stav    Stav          Typ             N?zev rozhran?
-------------------------------------------------------------------------
Povoleno                      Vyhrazen?        Bluetooth Network
Povoleno                      Vyhrazen?        ETH0
Povoleno                      Vyhrazen?        WLAN0
Povoleno                      Vyhrazen?        Bezdr?tov? p?ipojen? k s?ti 4
Povoleno                      Vyhrazen?        Bezdr?tov? p?ipojen? k s?ti 2
Povoleno                      Vyhrazen?        Hamachi
Povoleno                      Vyhrazen?        Bezdr?tov? p?ipojen? k s?ti 3
Povoleno                      Vnit?n?          Vnit?n?
Povoleno                      Zp?tn? smy?ka    Zp?tn? smy?ka
--------------------------------------------------------------------------

Output from real FOR /F command is:

-----------------------------------------------------------
c:\>echo Stav Typ             N?zev rozhran?
Stav Typ             N?zev rozhran?

c:\>echo Bluetooth Network
Bluetooth Network

c:\>echo ETH0
ETH0

c:\>echo WLAN0
WLAN0

c:\>echo Bezdr?tov? p?ipojen? k s?ti 4
Bezdr?tov? p?ipojen? k s?ti 4

c:\>echo Bezdr?tov? p?ipojen? k s?ti 2
Bezdr?tov? p?ipojen? k s?ti 2

c:\>echo Hamachi
Hamachi

c:\>echo Bezdr?tov? p?ipojen? k s?ti 3
Bezdr?tov? p?ipojen? k s?ti 3

c:\>echo Vnit?n?
Vnit?n?

c:\>echo smy?ka Zp?tn? smy?ka
smy?ka Zp?tn? smy?ka
----------------------------------------------------------

on last line you can see: "back Loop back" instead of "Loop back" or


even when

ojesth=A0 Interface Name---=A0 =A0dummy=A0 =A0Local Area Connection=A0 =A0

Tom Lavedas replied to Petr Laznovsky
19-Nov-09 10:37 AM
o
j
esth
=A0 Interface Name
---
=A0 =A0dummy
=A0 =A0Local Area Connection
=A0 =A0 Internal
=A0 =A0Loop Back
e of
ng:
=E1zev rozhran=ED
=A0 =A0Bluetooth Network
=A0 =A0ETH0
=A0 =A0WLAN0
=A0 =A0Bezdr=E1tov=E9 p=F8ipojen=ED k s=EDti 4
=A0 =A0Bezdr=E1tov=E9 p=F8ipojen=ED k s=EDti 2
=A0 =A0Hamachi
=A0 =A0Bezdr=E1tov=E9 p=F8ipojen=ED k s=EDti 3
=A0 =A0 =A0Vnit=F8n=ED
=A0 =A0Zp=ECtn=E1 smy=E8ka
-
Post Question To EggHeadCafe