Board logo

标题: [文本处理] [已解决]批处理输入变量,比对2个文本,存在显示‘已存在’,不存在‘写入文件’ [打印本页]

作者: thp2008    时间: 2021-3-30 09:52     标题: [已解决]批处理输入变量,比对2个文本,存在显示‘已存在’,不存在‘写入文件’

本帖最后由 thp2008 于 2021-3-31 11:32 编辑

我想写个输入后比对两个库文件的批处理,请帮我完善一下。

1、Ku01.txt
https://www.xigua.com/view_video.php?view=m604a630edd040
https://www.xigua.com/view_video.php?view=m60261926f38a5
https://www.xigua.com/view_video.php?view=m5fdcb7249a004
https://www.xigua.com/view_video.php?view=m5e80d9ed27871
https://www.xigua.com/view_video.php?view=m5f9c775cb3dc1
https://www.xigua.com/view_video.php?view=m6057900f86d5e
........................
此处省略N行

2、Ku02.txt
https://www.xigua.com/view_video.php?view=m605cd58a890b3
https://www.xigua.com/view_video.php?view=m5f70cc4b8f31b
https://www.xigua.com/view_video.php?view=m6055ce153a579
https://www.xigua.com/view_video.php?view=m6031dad48532b
https://www.xigua.com/view_video.php?view=m5e29b1373d0f1
https://www.xigua.com/view_video.php?view=m6044dd19361f6
........................
此处省略N行
  1. @echo off
  2. :jixiu
  3. set /P urllink=请输入链接地址:[url]https://www.xigua.com/view_video.php?view=m60271ee9c3642[/url]  这里模拟我输入的内容
  4. 如果 %urllink% 在 Ku01.txt 中存在,就显示 echo %urllink%  已存在Ku01.txt中
  5. 如果 %urllink% 在 Ku02.txt 中存在,就显示 echo %urllink%  已存在Ku02.txt中,如果存在,显示完成后就 goto jixiu  不存在,就继续执行。
  6. 如果两个库文件比对都不存在的话,就写入(追加)到List.txt文件最后。
  7. echo %urllink% >>list.txt
  8. echo %urllink% 已写入list.txt
  9. goto jixiu
复制代码

作者: went    时间: 2021-3-31 11:20

  1. @echo off & cd /d "%~dp0"
  2. :jixiu
  3. set /p "urllink=请输入链接地址: "
  4. REM txt文件列表
  5. set "txts=Ku01.txt Ku02.txt"
  6. set "find=false"
  7. for %%i in (%txts%) do (
  8. findstr /i /C:"%urllink%" "%%~i" >nul 2>nul && (
  9. echo %urllink%  已存在%%i中
  10. set "find=true"
  11. )
  12. )
  13. if "%find%"=="false" (
  14. echo %urllink%>>List.txt
  15. echo %txts% 中都不存在,已写入List.txt
  16. )
  17. pause & cls & goto :jixiu
复制代码

作者: thp2008    时间: 2021-3-31 11:31

回复 2# went


    完美,感谢大佬,这代码写的好。完全满足要求!




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2