togarha
togarha

Reputation: 175

Using percent symbol in token delimiter batch file

I'm trying to get the ipV6 address from an interface using a batch file in windows7 (through netsh command), but I don't know how can I put the % as delimiter: This is why I have:

FOR /F "tokens=1,2,3 delims= " %%A IN ('netsh int ipv6 show address "%IFACEWAN%" ^| FIND "Parameters"') DO (
    SET WANNIC.IPV6=%%B
)

And the result is:

WANNIC.IPV6=0000::aaaa:bbbb:cccc:dddd%12

but I want to remove the final "%12" from the result. I try to use % as delimiter, but it doesn't work:

| was unexpected at this time.

I try to use %% , ^%, and others, but I have no result. How can I use this symbol as delimiter? There is any other way to remove this part?

Thanks,

Upvotes: 3

Views: 511

Answers (1)

npocmaka
npocmaka

Reputation: 57262

you need to double it and left the space as the last delimiter:

FOR /F "tokens=1,2,3 delims=%% " %%A IN ('netsh int ipv6 show address "%IFACEWAN%" ^| FIND "Parameters"') DO (
    SET WANNIC.IPV6=%%B
)

E.g. This line works for me:

for /f "tokens=1,2,3,4,5 delims=%% " %%a in ('netsh int ipv6 show address^|find /i "infinite"') do echo %%e

Upvotes: 3

Related Questions