我有两个文本文件,all_codes.txt和downloaded_codes.txt,我想比较两个文本文件,并记录下download_codes.txt中是否缺少任何字符串
> all_codes.txt将包含以下字符串
A1
A2
A3
> Downloaded_codes.txt将包含以下字符串
A1
A3
在此示例中,downloadd_codes.txt中缺少A2 ,所以如果download_codes.txt中存在A2 ,我想在log.txt中记录“否” ,然后我想在log.txt中记录“ YES”。
这是我尝试过的,没有得到正确的结果:
@echo off
setlocal enabledelayedexpansion
for / f "delims=~" % % h in (All_codes.txt) do
for % % a in (downloaded_codes.txt) do(
set found = false
for / f "skip=2 tokens=*" % % b in ('findstr /i "%%h" "%%a"') do(
if "!found!" == "false" ((echo YES > log.txt
else(echo NO > log.txt)
set found = true
))
)
@echo off
findstr /V /G:Downloaded_codes.txt all_codes.txt > NUL
(if errorlevel 1 (echo YES) else echo NO) > log.txt
编辑:这是一个示例会话:
C:\> type test.bat
@echo off
findstr /V /G:Downloaded_codes.txt all_codes.txt > NUL
(if errorlevel 1 (echo YES) else echo NO)
C:\> type all_codes.txt
A1
A2
A3
C:\> type Downloaded_codes.txt
A1
C:\> test
NO
C:\> echo A3>> Downloaded_codes.txt
C:\> type Downloaded_codes.txt
A1
A3
C:\> test
NO
C:\> echo A2>> Downloaded_codes.txt
C:\> type Downloaded_codes.txt
A1
A3
A2
C:\> test
YES
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句