Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 609
togarha Avatar asked Nov 29 '25 14:11

togarha


1 Answers

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
like image 144
npocmaka Avatar answered Dec 01 '25 10:12

npocmaka