中国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-09-15 12:31
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » {Solved} How to compare file contents - for comparing MAC addresses
Printable Version  3,911 / 22
Floor1 chainliq Posted 2007-03-10 11:01
高级用户 Posts 244 Credits 635 From 广西贵港
The content in the question is mainly about how to write a batch processing program to compare the MAC addresses in two text files and handle the situation where the MAC address changes. The following is a possible batch processing code idea (for reference only, may need to be adjusted according to actual situations):

```batch
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:" %%a in (a.txt) do (
set "ip_a=%%a"
set "mac_a=%%b"
for /f "tokens=1,2 delims=:" %%c in (b.txt) do (
if "%%c"=="!ip_a!" (
if not "%%d"=="!mac_a!" (
echo!ip_a!:!mac_a!>>1.txt
)
goto next
)
)
:next
)
endlocal
```

Please note that this is a simple implementation idea. In actual use, it may need to be further optimized and adjusted according to more complex actual situations.
Floor2 youxi01 Posted 2007-03-10 12:28
高级用户 Posts 247 Credits 846 From 湖南==》广东
Other projects, such as: 192.168.2.1, 192.168.2.3, etc. Do you not need to check?
Floor3 lxmxn Posted 2007-03-10 12:32
版主 Posts 4,938 Credits 11,386



[最后编辑于2007-3-10 下午06:10由lxmxn]
Floor4 youxi01 Posted 2007-03-10 12:53
高级用户 Posts 247 Credits 846 From 湖南==》广东
Also post a paragraph to play:

Floor5 chainliq Posted 2007-03-10 22:34
高级用户 Posts 244 Credits 635 From 广西贵港
Originally posted by youxi01 at 2007-3-10 12:28:
Other items, such as: 192.168.2.1, 192.168.2.3, etc., do they not need to be checked?



Need to, otherwise, it would be easy to do, ``What needs to be checked are hundreds of MACs``
Floor6 chainliq Posted 2007-03-10 22:39
高级用户 Posts 244 Credits 635 From 广西贵港
Brother lxmxn, it seems like it didn't respond after running.
Floor7 ccwan Posted 2007-03-10 22:57
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
```
@echo off
for /f "tokens=1* delims=-" %%i in (a.txt) do (
for /f "tokens=1* delims=-" %%a in (b.txt) do (
if "%%i"=="%%a" if not "%%j"=="%%b" >>1.txt echo %%a-%%b
)
)
pause
```
Floor8 test266 Posted 2007-03-10 23:07
初级用户 Posts 10 Credits 22
@echo off
rem The order of IP can be scrambled
setlocal ENABLEDELAYEDEXPANSION
set t1=!time!

set /a num=1
for /f "tokens=1,2 delims=:" %%i in (b.txt) do (
set ip!num!=%%i
set mac!num!=%%j
set /a num+=1
)

for /f "tokens=1,2 delims=:" %%i in (a.txt) do (
for /L %%a in (1,1,!num!) do (
if "!ip%%a!"=="%%i" (
if not "!mac%%a!"=="%%j" echo !ip%%a!:!mac%%a! vs %%i:%%j
)
)
)


echo Number of comparison lines:%num%
echo Start time:%t1%
echo End time:!time!
Floor9 chainliq Posted 2007-03-10 23:13
高级用户 Posts 244 Credits 635 From 广西贵港
Hehe, there are really many experts. Well, I didn't use it properly just now. Actually, Brother lxmxn's one can be used. Thanks to everyone. The others are also good. Well, ashamed. I need to learn from you all. I tried, and they all work. hehe
Floor10 test266 Posted 2007-03-10 23:35
初级用户 Posts 10 Credits 22
The code on the 4th floor is really extremely efficient. I admire it!
Floor11 slore Posted 2007-03-11 02:41
铂金会员 Posts 2,478 Credits 5,212
Originally posted by test266 at 2007-3-10 10:35:
The code on floor 4 is really efficient, I admire it!


Sweat~ #4 seems to only check whether that one is equal... If you change others, it doesn't care... A failed code... Don't mention efficiency.

◎echo off
echo XXX.XX.XX.X
exit
What about this efficiency? Sweat~
Floor12 youxi01 Posted 2007-03-11 03:14
高级用户 Posts 247 Credits 846 From 湖南==》广东
The brother who went upstairs seems to have not understood the code.
Floor13 slore Posted 2007-03-11 03:34
铂金会员 Posts 2,478 Credits 5,212
if defined flag (echo 192.168.2.2's MAC has been changed.) else echo 192.168.2.2's MAC has not been changed.

What would your code output if 192.168.2.3 changes?

Either do both or don't be redundant. Just echo %%i %j directly.

Have you tried the fc a.txt b.txt command?
Floor14 ccwan Posted 2007-03-11 03:48
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Don't argue anymore. Everyone has different ways to solve problems, which is a good thing and can broaden ideas, isn't it?

Let me solve it with one sentence.
Floor15 youxi01 Posted 2007-03-11 04:35
高级用户 Posts 247 Credits 846 From 湖南==》广东
Hehe, back.

The original meaning of my text is to first find out all the changed macs,
and then judge whether the mac of IP 192.168.2.2 has changed.

The original idea is that this might be more in line with the landlord's meaning, maybe I was wrong.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023