|
chainliq
高级用户
    学无尽止
积分 635
发帖 244
注册 2006-4-15 来自 广西贵港
状态 离线
|
『楼 主』:
{已结}请问如何比较文件内容-用于比较MAC地址
使用 LLM 解释/回答一下
文件a.txt里的内容如下:
192.168.2.1:00-E0-4C-F7-0C-E5
192.168.2.2:00-E0-4C-F7-0C-E3
192.168.2.3:00-E0-4C-F7-05-E4
192.168.2.4:00-E0-4C-F6-A8-BB
192.168.2.5:00-E0-4C-F7-05-E5
192.168.2.6:00-E0-4C-F5-E3-A1
192.168.2.7:00-E0-4C-F6-CD-06
192.168.2.8:00-E0-4C-F7-0C-F3
192.168.2.9:00-E0-4C-F5-E2-FD
文件b.txt里的内容如下:
192.168.2.1:00-E0-4C-F7-0C-E5
192.168.2.2:00-00-4C-F7-0C-E3
192.168.2.3:00-E0-4C-F7-05-E4
192.168.2.4:00-E0-4C-F6-A8-BB
192.168.2.5:00-E0-4C-F7-05-E5
192.168.2.6:00-E0-4C-F5-E3-A1
192.168.2.7:00-E0-4C-F6-CD-06
192.168.2.8:00-E0-4C-F7-0C-F3
192.168.2.9:00-E0-4C-F5-E2-FD
效果,如文件b.txt中的IP:192.168.2.2: 与文件a.txt中的IP:192.168.2.2: 这一行相比,如发现在后面的MAC地址改变则>>1.txt 请问批处理怎么做呀
Last edited by chainliq on 2007-3-10 at 11:14 PM ]
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.
|

学无尽止 |
|
2007-3-10 11:01 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
其它的项目,比如:192.168.2.1,192.168.2.3等不需要检查吗?
Other projects, such as: 192.168.2.1, 192.168.2.3, etc. Do you not need to check?
|
|
2007-3-10 12:28 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
 『第 3 楼』:
使用 LLM 解释/回答一下
@echo off
if exist 1.txt del 1.txt
for /f "delims=: tokens=1*" %%a in (a.txt) do (
for /f "delims=" %%_ in ('findstr "%%a" b.txt') do (
if NOT "%%a:%%b"=="%%_" >>1.txt echo %%_
)
)
start 1.txt
Last edited by lxmxn on 2007-3-10 at 06:10 PM ]
@echo off
if exist 1.txt del 1.txt
for /f "delims=: tokens=1*" %%a in (a.txt) do (
for /f "delims=" %%_ in ('findstr "%%a" b.txt') do (
if NOT "%%a:%%b"=="%%_" >>1.txt echo %%_
)
)
start 1.txt
最后编辑于2007-3-10 下午06:10由lxmxn]
|
|
2007-3-10 12:32 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
也贴一段来玩玩:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:" %%i in (a.txt) do set "%%i=%%j"
echo ============================
echo 文档a.txt和b.txt中的mac改动的有:
echo.
for /f "tokens=1,2 delims=:" %%i in (b.txt) do (
if /i not "!%%i!"=="%%j" (
echo %%i %%j
if "%%i"=="192.168.2.2" set flag=1
)
)
echo -----------------------------
echo 其中:
if defined flag (echo 192.168.2.2 之 mac已经改动。) else 192.168.2.2 之mac未改动。
echo ==============================
pause>nul
Also post a paragraph to play:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:" %%i in (a.txt) do set "%%i=%%j"
echo ============================
echo The MAC changes in documents a.txt and b.txt are:
echo.
for /f "tokens=1,2 delims=:" %%i in (b.txt) do (
if /i not "!%%i!"=="%%j" (
echo %%i %%j
if "%%i"=="192.168.2.2" set flag=1
)
)
echo -----------------------------
echo Among them:
if defined flag (echo The MAC of 192.168.2.2 has been changed.) else echo The MAC of 192.168.2.2 has not been changed.
echo ==============================
pause>nul
|
|
2007-3-10 12:53 |
|
|
chainliq
高级用户
    学无尽止
积分 635
发帖 244
注册 2006-4-15 来自 广西贵港
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by youxi01 at 2007-3-10 12:28:
其它的项目,比如:192.168.2.1,192.168.2.3等不需要检查吗?
要呀,要不然,那样就好做喽,``要检查的是几百向MAC呀``
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``
|

学无尽止 |
|
2007-3-10 22:34 |
|
|
chainliq
高级用户
    学无尽止
积分 635
发帖 244
注册 2006-4-15 来自 广西贵港
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
lxmxn 兄弟的好像运行啦没反应哦`
Brother lxmxn, it seems like it didn't respond after running.
|

学无尽止 |
|
2007-3-10 22:39 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
@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
```
@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
```
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-3-10 22:57 |
|
|
test266
初级用户
 
积分 22
发帖 10
注册 2007-2-16
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
@echo off
rem ip的顺序可以打乱
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 比较行数:%num%
echo 开始时间:%t1%
echo 结束时间:!time!
@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!
|
|
2007-3-10 23:07 |
|
|
chainliq
高级用户
    学无尽止
积分 635
发帖 244
注册 2006-4-15 来自 广西贵港
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
呵呵,高手真多哦,``哎,刚才是我没用好,其实lxmxn兄的是可以用的```谢谢各位哦,其他各位的也不错,哎,惭愧哈,要向你们学习学习`,试过啦`都行`呵呵``
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
|

学无尽止 |
|
2007-3-10 23:13 |
|
|
test266
初级用户
 
积分 22
发帖 10
注册 2007-2-16
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
4楼的代码,效率实在是太高了,佩服啊!!
The code on the 4th floor is really extremely efficient. I admire it!
|
|
2007-3-10 23:35 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by test266 at 2007-3-10 10:35:
4楼的代码,效率实在是太高了,佩服啊!!
汗~#4貌似只检测那一个是不是相等……你改其他的就不管。。。失败的代码……不要提什么效率。
◎echo off
echo XXX.XX.XX.X
exit
这个效率呢?汗~
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~
|
|
2007-3-11 02:41 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
上楼的兄弟才好似没看懂代码吧
The brother who went upstairs seems to have not understood the code.
|
|
2007-3-11 03:14 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
if defined flag (echo 192.168.2.2 之 mac已经改动。) else 192.168.2.2 之mac未改动。
如果192.168.2.3改变了呢?你的代码输出什么?
要么都做要么就不要画蛇添足。。不要加这个直接echo %%i %j就好了。
fc a.txt b.txt命令试过么?
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?
|
|
2007-3-11 03:34 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
不要争论啦,每个人解决问题的方法不一样,这是好事,可以开阔思路不是吗?
我来一句话解决它吧。 findstr /v /g:b.txt a.txt >1.txt
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.
findstr /v /g:b.txt a.txt >1.txt
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-3-11 03:48 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
呵呵,回来了。
本人原文的意思是先找出所有的已经改动的 mac,
然后再判断 IP 192.168.2.2 的mac是否改动。
原来的想法是这样可能更贴切楼主的意思,可能是我错了。
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.
|
|
2007-3-11 04:35 |
|