Board logo

标题: [文本处理] [已解决]批处理如何提取txt文本中含有特定字符串的行内容? [打印本页]

作者: samsung4203    时间: 2015-1-19 09:22     标题: [已解决]批处理如何提取txt文本中含有特定字符串的行内容?

本帖最后由 pcl_test 于 2016-8-13 20:50 编辑

批处理如何获取TXT中设备下面标示符的字符串?
这是Windows8.1 BCD中的内容 我想获取TXT中【设备选项】下面标识符的字符串 【{e9aa8814-419f-11e4-972a-f4ce4698d370} 】并输出到b.txt 这只是个范例 可能其它BCD中字符串就不在这一行了 最好不要用行数来识别字符串,谢谢!
  1. Windows 启动管理器
  2. --------------------
  3. 标识符                  {bootmgr}
  4. device                  partition=C:
  5. description             Windows Boot Manager
  6. locale                  zh-CN
  7. inherit                 {globalsettings}
  8. integrityservices       Enable
  9. default                 {current}
  10. resumeobject            {e9aa8811-419f-11e4-972a-f4ce4698d370}
  11. displayorder            {current}
  12. toolsdisplayorder       {memdiag}
  13. timeout                 30
  14. Windows 启动加载器
  15. -------------------
  16. 标识符                  {current}
  17. device                  partition=C:
  18. path                    \Windows\system32\winload.exe
  19. description             Windows 8.1
  20. locale                  zh-CN
  21. inherit                 {bootloadersettings}
  22. recoverysequence        {e9aa8813-419f-11e4-972a-f4ce4698d370}
  23. integrityservices       Enable
  24. recoveryenabled         Yes
  25. allowedinmemorysettings 0x15000075
  26. osdevice                partition=C:
  27. systemroot              \Windows
  28. resumeobject            {e9aa8811-419f-11e4-972a-f4ce4698d370}
  29. nx                      OptIn
  30. bootmenupolicy          Standard
  31. Windows 启动加载器
  32. -------------------
  33. 标识符                  {e9aa8813-419f-11e4-972a-f4ce4698d370}
  34. device                  ramdisk=[C:]\Recovery\WindowsRE\Winre.wim,{e9aa8814-419f-11e4-972a-f4ce4698d370}
  35. path                    \windows\system32\winload.exe
  36. description             Windows Recovery Environment
  37. locale                  zh-cn
  38. inherit                 {bootloadersettings}
  39. displaymessage          Recovery
  40. displaymessageoverride  Recovery
  41. osdevice                ramdisk=[C:]\Recovery\WindowsRE\Winre.wim,{e9aa8814-419f-11e4-972a-f4ce4698d370}
  42. systemroot              \windows
  43. nx                      OptIn
  44. bootmenupolicy          Standard
  45. winpe                   Yes
  46. 从休眠状态恢复
  47. ---------------------
  48. 标识符                  {e9aa8811-419f-11e4-972a-f4ce4698d370}
  49. device                  partition=C:
  50. path                    \Windows\system32\winresume.exe
  51. description             Windows Resume Application
  52. locale                  zh-CN
  53. inherit                 {resumeloadersettings}
  54. recoverysequence        {e9aa8813-419f-11e4-972a-f4ce4698d370}
  55. recoveryenabled         Yes
  56. allowedinmemorysettings 0x15000075
  57. filedevice              partition=C:
  58. filepath                \hiberfil.sys
  59. bootmenupolicy          Standard
  60. pae                     Yes
  61. debugoptionenabled      No
  62. Windows 内存测试程序
  63. ---------------------
  64. 标识符                  {memdiag}
  65. device                  partition=C:
  66. path                    \boot\memtest.exe
  67. description             Windows 内存诊断
  68. locale                  zh-CN
  69. inherit                 {globalsettings}
  70. badmemoryaccess         Yes
  71. EMS 设置
  72. ------------
  73. 标识符                  {emssettings}
  74. bootems                 No
  75. 调试器设置
  76. -----------------
  77. 标识符                  {dbgsettings}
  78. debugtype               Serial
  79. debugport               1
  80. baudrate                115200
  81. RAM 故障
  82. -----------
  83. 标识符                  {badmemory}
  84. 全局设置
  85. ---------------
  86. 标识符                  {globalsettings}
  87. inherit                 {dbgsettings}
  88.                         {emssettings}
  89.                         {badmemory}
  90. 启动加载器设置
  91. --------------------
  92. 标识符                  {bootloadersettings}
  93. inherit                 {globalsettings}
  94.                         {hypervisorsettings}
  95. 虚拟机监控程序设置
  96. -------------------
  97. 标识符                  {hypervisorsettings}
  98. hypervisordebugtype     Serial
  99. hypervisordebugport     1
  100. hypervisorbaudrate      115200
  101. 恢复加载器设置
  102. ----------------------
  103. 标识符                  {resumeloadersettings}
  104. inherit                 {globalsettings}
  105. 设备选项
  106. --------------
  107. 标识符                  {e9aa8814-419f-11e4-972a-f4ce4698d370}
  108. description             Windows Recovery
  109. ramdisksdidevice        partition=C:
  110. ramdisksdipath          \Recovery\WindowsRE\boot.sdi
复制代码

作者: xxpinqz    时间: 2015-1-19 09:53

文档规范的话,可以试试这样:
  1. @echo off&setlocal enabledelayedexpansion
  2. (for /f "tokens=1*" %%a in ('findstr /i "设备选项 标识符" a.txt') do (
  3.     if defined flag if "%%a"=="标识符" echo,%%b
  4.     if "%%a"=="设备选项" (set flag=1) else set "flag="
  5. ))>b.txt
复制代码

作者: samsung4203    时间: 2015-1-19 10:04     标题: 已解决! 请教! 如何获取TXT中设备下面标示符的字符串

回复 2# xxpinqz


    非常感谢 xxpinqz 的帮助 代码成功了




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