China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-06 01:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » If it matches, display it; if not, continue running View 782 Replies 7
Original Poster Posted 2007-09-29 17:59 ·  中国 广东 广州 花都区 电信
初级用户
★★
Credits 197
Posts 77
Joined 2006-09-19 14:02
19-year member
UID 63074
Gender Male
Status Offline
@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??
Floor 2 Posted 2007-09-29 18:10 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
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??
Floor 3 Posted 2007-09-29 18:19 ·  中国 广东 广州 花都区 电信
初级用户
★★
Credits 197
Posts 77
Joined 2006-09-19 14:02
19-year member
UID 63074
Gender Male
Status Offline
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"
Floor 4 Posted 2007-09-29 18:25 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
@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
Floor 5 Posted 2007-09-29 18:41 ·  中国 广东 广州 花都区 电信
初级用户
★★
Credits 197
Posts 77
Joined 2006-09-19 14:02
19-year member
UID 63074
Gender Male
Status Offline
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
Floor 6 Posted 2007-09-29 18:46 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Search for it yourself, there are quite a lot of similar ones in the forum.
Floor 7 Posted 2007-09-29 18:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline

@echo off
:lis
set str=0
set /p var=Please enter:
for /f "tokens=1* delims= " %%a in ("%var%") do set var1=%%a
for /f "tokens=1* delims= " %%c in (test.txt) do (
if "%var1%"=="%%c" echo %%c exists&set str=1
if "%var1%"=="%%c" (echo %var%>>_test.txt) else echo %%c %%d>>_test.txt
)
if "%str%"=="0" cls&&echo Input error&&goto lis
del/q test.txt
ren _test.txt test.txt
致精致简!
Floor 8 Posted 2007-09-30 01:05 ·  中国 广东 广州 花都区 电信
初级用户
★★
Credits 197
Posts 77
Joined 2006-09-19 14:02
19-year member
UID 63074
Gender Male
Status Offline
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??
Forum Jump: