中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-06 00:17
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » If it matches, display it; if not, continue running
Printable Version  780 / 7
Floor1 bbq123bbq Posted 2007-09-29 17:59
初级用户 Posts 77 Credits 197
@echo off
set /p ip=Enter IP address
for /f "tokens=1,2 delims= " %%i in (test.txt) do (
if %ip%==%%i (echo %ip% %%j)

test.txt
192.168.0.4 00-1C-F1-00-65-7F
192.168.0.238 00-1C-F1-00-68-84
192.168.0.42 00-1C-F1-00-69-54
192.168.0.41 00-1C-F1-00-97-80
192.168.0.22 00-1C-F1-00-68-80

If the entered IP matches an IP in test, then display the corresponding IP and MAC. If it doesn't match, then continue to the next step...... How should this be written??
Floor2 wudixin96 Posted 2007-09-29 18:10
银牌会员 Posts 931 Credits 1,928
Continue to the next step??? What do you mean? Which step??

Does the OP mean: find the line in test.txt that has the same IP as the entered one??

Or??
Floor3 bbq123bbq Posted 2007-09-29 18:19
初级用户 Posts 77 Credits 197
Enter an IP
If the entered IP exists in test, then display "IP exists". If the entered IP is not in test, then display "IP is incorrect, re-enter it"
Floor4 wudixin96 Posted 2007-09-29 18:25
银牌会员 Posts 931 Credits 1,928
@echo off
set /p ip=Enter IP address:
findstr /i "\<%ip%\>" test.txt>nul 2>nul&&findstr /i "\<%ip%\>" test.txt||echo IP input error!
pause
Floor5 bbq123bbq Posted 2007-09-29 18:41
初级用户 Posts 77 Credits 197
Based on the entered IP and MAC... change the corresponding IP and MAC.... What I mean is, if I enter 192.168.0.4 00-1C-F1-00-67-8E, and if the IP 192.168.0.4 exists in test, then replace the 192.168.0.4 00-1C-F1-00-65-7F in test with 192.168.0.4 00-1C-F1-00-67-8E
Floor6 wudixin96 Posted 2007-09-29 18:46
银牌会员 Posts 931 Credits 1,928
Search for it yourself, there are quite a lot of similar ones in the forum.
Floor7 26933062 Posted 2007-09-29 18:59
银牌会员 Posts 879 Credits 2,268
Floor8 bbq123bbq Posted 2007-09-30 01:05
初级用户 Posts 77 Credits 197
Problem solved... thanks... but there's one part of the code in post #7 that I don't understand??
if "%var1%"=="%%c" (echo %var%>>_test.txt) else echo %%c %%d>>_test.txt
Doesn't else here mean that echo %%c %%d>>_test.txt is executed only when if "%var1%"=="%%c" (echo %var%>>_test.txt) is not true??
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023