Batch file 查找两个文本文件批处理脚本中的差异列表
她就是我想做的。我有包含数据列表的LISTa(data.txt)和包含另一个数据列表的LISTb(has.txt)。我想比较LISTa(data.txt)和LISTb(has.txt),并确定LISTa(data.txt)中的哪些内容不在LISTb(has.txt)中。我尝试了以下方法,但没有成功。我认为这是因为两个列表都包含数字Batch file 查找两个文本文件批处理脚本中的差异列表,batch-file,Batch File,她就是我想做的。我有包含数据列表的LISTa(data.txt)和包含另一个数据列表的LISTb(has.txt)。我想比较LISTa(data.txt)和LISTb(has.txt),并确定LISTa(data.txt)中的哪些内容不在LISTb(has.txt)中。我尝试了以下方法,但没有成功。我认为这是因为两个列表都包含数字 Findstr /ivg:"%home%\has.txt" "%home%\data.txt" > %home%\final.txt 但我得到的只是一张空白名
Findstr /ivg:"%home%\has.txt" "%home%\data.txt" > %home%\final.txt
但我得到的只是一张空白名单
我已经让它与下面的代码一起工作,但想知道是否有更容易的事情,因为当完成时,这将比较列表中的数千行
for /f %%a in (%home%\has.txt) do CALL :sub1 %%a
GOTO EOF
:sub1
ECHO IN sub1
findstr /iv "%1" "%home%\data.txt" > %home%\final.txt
del %home%\data.txt /q
rename %home%\final.txt data.txt
exit /b
我会看到你的。它确保对整行进行匹配,因此
data.txt
中的123
与has.txt中的2
不匹配has.txt
那么FC
命令呢?谢谢。使用此代码执行不同的函数FasterHanks。这是快速和简单的。
@echo off
setlocal
rem Load lines from data.txt
for /F %%a in (%home%\data.txt) do set line[%%a]=1
rem Delete lines from has.txt
for /F %%a in (%home%\has.txt) do set "line[%%a]="
rem Show the rest, that is, lines in data.txt that was not in has.txt
(for /F "tokens=2 delims=[]" %%a in ('set line[') do echo %%a) > %home%\final.txt
Findstr /b /e /ivg:"%home%\has.txt" "%home%\data.txt" > %home%\final.txt