找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 25708|回复: 4

[文本处理] [已解决]批处理如何提取文本每行以KB开头,数字结尾?

[复制链接]
发表于 2013-5-18 17:24:23 | 显示全部楼层 |阅读模式
我想提取文本文件每行以KB开头,数字结尾的批处理,KB是固定的,结尾数字不等,提取后另存为kb.txt,然后按kb.txt中的内容复制文件夹中包含关键字的文件到新的文件夹.

例如:提取后在kb.txt中有"KB2727528"这个关键字,当前文件夹中有包含"KB2727528"关键字的文件"Windows8-RT-KB2727528-x64.msu",然后移动包含"KB2727528"关键字的文件到新的文件夹并输出移动成功和找不到文件的日志文件!
  1. Microsoft Pinyin SimpleFast popular words dictionary 更新 (KB2723161)
  2. Microsoft Pinyin SimpleFast popular words dictionary 更新 (KB2723161)
  3. Microsoft Pinyin SimpleFast popular words dictionary 更新 (KB2723161)
  4. 适用于 Windows 8(基于 x64 的系统)的 Microsoft 相机编解码包更新 (KB2779444)
  5. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2727528)
  6. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2753842)
  7. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2757638)
  8. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2770660)
  9. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2781197)
  10. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2785220)
  11. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2790655)
  12. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2807986)
  13. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2808735)
  14. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2829254)
  15. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2829361)
  16. 用于基于 x64 的系统的 Windows 8 安全更新程序 (KB2830290)
  17. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2768703)
  18. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2769034)
  19. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2769165)
  20. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2771431)
  21. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2772501)
  22. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2777294)
  23. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2795944)
  24. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2798162)
  25. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2800033)
  26. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2805966)
  27. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2811660)
  28. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2820330)
  29. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2822241)
  30. 用于基于 x64 的系统的 Windows 8 更新程序 (KB2836988)
  31. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 安全更新程序 (KB2729462)
  32. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 安全更新程序 (KB2736693)
  33. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 安全更新程序 (KB2742616)
  34. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 安全更新程序 (KB2756923)
  35. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 安全更新程序 (KB2789650)
  36. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 安全更新程序 (KB2804584)
  37. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 安全更新程序 (KB2737084)
  38. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 安全更新程序 (KB2742614)
  39. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 安全更新程序 (KB2789649)
  40. 用于基于 x64 的系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 安全更新程序 (KB2804583)
  41. 用于基于 x64 的系统的 Windows 8 中 ActiveX Killbit 累积安全更新程序 (KB2820197)
  42. 用于基于 x64 系统的 Windows 8 的 Internet Explorer 10 的累积安全更新程序 (KB2829530)
  43. 用于基于 x64 系统的 Windows 8 的 Internet Explorer Flash Player 的安全更新程序 (KB2837385)
  44. 此更新可修复 Microsoft 安全公告 (KB2837385) 中公布的漏洞。经证实,如果计算机正在运行适用于 Windows 8 的 Internet Explorer Flash Player,则攻击者可利用这些安全问题危害该计算机的安全,并对该计算机加以控制。可通过安装 Microsoft 提供的此更新来帮助保护您的计算机。安装此更新后,可能需要重新启动计算机。
  45. 用于基于 x64 系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 3.5 更新程序 (KB2769166)
  46. 用于基于 x64 系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 更新程序 (KB2750149)
  47. 用于基于 x64 系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 更新程序 (KB2805222)
  48. 用于基于 x64 系统的 Windows 8 和 Windows Server 2012 的 Microsoft .NET Framework 4.5 更新程序 (KB2805227)
复制代码

评分

参与人数 1PB +2 收起 理由
Batcher + 2 感谢给帖子标题标注[已解决]字样

查看全部评分

发表于 2013-5-18 17:50:27 | 显示全部楼层
假设上述文档名为1.txt

  1. @echo off
  2. (for /f "tokens=2 delims=B" %%a in (1.txt) do (
  3.   for /f "delims=)" %%b in ("%%a") do echo KB%%b
  4. ))>kb.txt
  5. start kb.txt
复制代码

评分

参与人数 1技术 +1 收起 理由
Batcher + 1 乐于助人

查看全部评分

 楼主| 发表于 2013-5-18 18:04:17 | 显示全部楼层
回复 2# xxpinqz

多谢xxpinqz! 我测试提取没问题,我又补充了一点内容您看能解决吗?
发表于 2013-5-18 22:24:58 | 显示全部楼层
这样试下:
  1. @echo off
  2. md "New" 2>nul
  3. for /f "tokens=2 delims=()" %%a in (1.txt) do (
  4.    echo %%a>>kb.txt
  5.    if exist "*%%a*" (
  6.       move "*%%a*" "New">>ok.log
  7.    ) else (
  8.       echo 找不到*%%a*文件>>nok.log
  9.    )
  10. )
  11. pause
复制代码

评分

参与人数 1技术 +1 收起 理由
Batcher + 1 乐于助人

查看全部评分

 楼主| 发表于 2013-5-18 23:47:48 | 显示全部楼层
回复 4# apang

  谢谢apang大哥! 又一次解决了我的难题! 非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 06:22 , Processed in 0.027724 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表