我正在运行此命令:
for /f "tokens=2 delims=:" %%a in ('ipconfig /all^|find "IPv4 Address"') do (
set ip=%%a
goto :IPaddress1
)
:IPaddress1
echo ip1:%ip: =% >>"Z:\Retrievedinfo\untrimmedIP.txt"
我在untrimmed.txt文件中得到了这个结果:
ip1:192.168.111.1(Preferred)
我用什么代码修剪"(首选)"从最后,我留下了:
ip1:192.168.111.1
答案 0 :(得分:0)
您可以将文字替换为以下内容:
for /f "tokens=2 delims=:" %%a in ('ipconfig /all^|find "IPv4 Address"') do ( set ip=%%a goto :IPaddress1 ) :IPaddress1 set ip=ip1:%ip:(Preferred)=% echo %ip: =% >>"Z:\Retrievedinfo\untrimmedIP.txt"
答案 1 :(得分:0)
你可以尝试这样的事情:
@echo off
echo(
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do (
set ip=%%b
)
set ip=%ip:~1%
echo(
echo The Local IPv4 adress is : %ip%
echo The Local IPv4 adress is : %ip% >>"Z:\Retrievedinfo\TrimmedIP.txt"
pause
答案 2 :(得分:0)
我只需将(
添加到分隔符列表中。
for /f "tokens=2 delims=:(" %%a in ('ipconfig /all^|find "IPv4 Address"') do set "ip=%%a"
set "ip=%ip:~1%"
使用子字符串操作的替代方法是使用第二个FOR / F循环去除前导空格
for /f "tokens=2 delims=:(" %%a in ('ipconfig /all^|find "IPv4 Address"') do for /f %%b in ("%%a") do set "ip=%%b"