[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理如何提取关键词所在行及其上下几行内容?

现有文本1.txt,内容如下
  1. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_IGNORE_XML_PROLOG]
  2. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_IMAGING_USE_ART]
  3. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_INTERNET_SHELL_FOLDERS]
  4. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LEGACY_DISPPARAMS]
  5. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LEGACY_DLCONTROL_BEHAVIORS]
  6. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN]
  7. "MSOSYNC.EXE"=dword:00000001
  8. "MSOUC.EXE"=dword:00000001
  9. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MAXCONNECTIONSPER1_0SERVER]
  10. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MAXCONNECTIONSPERSERVER]
  11. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MIME_HANDLING]
  12. "MSOSYNC.EXE"=dword:00000001
  13. "MSOUC.EXE"=dword:00000001
  14. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MIME_SNIFFING]
  15. "MSOSYNC.EXE"=dword:00000001
  16. "MSOUC.EXE"=dword:00000001
  17. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MSHTML_AUTOLOAD_IEFRAME]
  18. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_OBJECT_CACHING]
  19. "MSOSYNC.EXE"=dword:00000001
  20. "MSOUC.EXE"=dword:00000001
  21. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_PROTOCOL_LOCKDOWN]
  22. "MSOSYNC.EXE"=dword:00000001
  23. "MSOUC.EXE"=dword:00000001
  24. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RELEASE_CALLBACK_ON_STOP_BINDING]
  25. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_ABOUT_PROTOCOL_IE7]
  26. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_ACTIVEXINSTALL]
  27. "MSOSYNC.EXE"=dword:00000001
  28. "MSOUC.EXE"=dword:00000001
  29. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_FILEDOWNLOAD]
  30. "MSOSYNC.EXE"=dword:00000001
  31. "MSOUC.EXE"=dword:00000001
  32. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_OBJECT_DATA_ATTRIBUTE]
  33. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_RES_TO_LMZ]
  34. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SAFE_BINDTOOBJECT]
  35. "MSOSYNC.EXE"=dword:00000001
  36. "MSOUC.EXE"=dword:00000001
  37. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SECURITYBAND]
  38. "MSOSYNC.EXE"=dword:00000001
  39. "MSOUC.EXE"=dword:00000001
  40. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SHIM_MSHELP_COMBINE]
  41. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SHOW_APP_PROTOCOL_WARN_DIALOG]
  42. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SSLUX]
  43. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SUBDOWNLOAD_LOCKDOWN]
  44. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_UNC_SAVEDFILECHECK]
  45. "MSOSYNC.EXE"=dword:00000001
  46. "MSOUC.EXE"=dword:00000001
  47. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_USE_WINDOWEDSELECTCONTROL]
  48. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_VALIDATE_NAVIGATE_URL]
  49. "MSOSYNC.EXE"=dword:00000001
  50. "MSOUC.EXE"=dword:00000001
  51. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_VIEWLINKEDWEBOC_IS_UNSAFE]
  52. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WEBOC_MOVESIZECHILD]
  53. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WEBOC_POPUPMANAGEMENT]
  54. "MSOSYNC.EXE"=dword:00000001
  55. "MSOUC.EXE"=dword:00000001
  56. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WINDOW_RESTRICTIONS]
  57. "MSOSYNC.EXE"=dword:00000001
  58. "MSOUC.EXE"=dword:00000001
  59. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_XSSFILTER]
  60. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ZONE_ELEVATION]
  61. "MSOSYNC.EXE"=dword:00000001
  62. "MSOUC.EXE"=dword:00000001
  63. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\7660AEC6D8E6CFE42A4E2B964A5DC9E7]
  64. "00005119110000000100000000F01FEC"="C:\\Program Files\\Microsoft Office\\Office15\\MSOUC.EXE"
  65. [HKEY_USERS\S-1-5-21-787889350-1610004461-349859190-500\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU]
  66. "c"="regedit.exe /e MSOUC.EXE.reg\\1"
复制代码
1、现在想得到如下的结果:
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MIME_HANDLING]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_MIME_SNIFFING]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_OBJECT_CACHING]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_PROTOCOL_LOCKDOWN]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_ACTIVEXINSTALL]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_RESTRICT_FILEDOWNLOAD]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SAFE_BINDTOOBJECT]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SECURITYBAND]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_UNC_SAVEDFILECHECK]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_VALIDATE_NAVIGATE_URL]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WEBOC_POPUPMANAGEMENT]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WINDOW_RESTRICTIONS]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ZONE_ELEVATION]
"MSOSYNC.EXE"=dword:00000001
"MSOUC.EXE"=dword:00000001
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\7660AEC6D8E6CFE42A4E2B964A5DC9E7]
"00005119110000000100000000F01FEC"="C:\\Program Files\\Microsoft Office\\Office15\\MSOUC.EXE"
[-HKEY_USERS\S-1-5-21-787889350-1610004461-349859190-500\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU]
"c"="regedit.exe /e MSOUC.EXE.reg\\1"
先谢了!

本帖最后由 CrLf 于 2015-10-27 16:46 编辑

有意思,回家写个第三方
不过你要以什么依据来定位呢?

TOP

本帖最后由 pcl_test 于 2015-10-27 17:05 编辑
  1. //&cls&cscript -nologo -e:jscript "%~f0"<"1.txt"&pause&exit
  2. var m=WScript.StdIn.ReadAll().match(/\[[^\]]+?\]\r?\n[^\[]*?MSOUC\.EXE[^\[]*/g)
  3. for (var i=0; i<m.length; i++) WSH.echo(m[i].replace(/\[/g,'[-'));
复制代码
1

评分人数

    • suchost: 助人为乐,技术高超技术 + 1

TOP

本帖最后由 suchost 于 2015-10-27 16:52 编辑

回复 2# CrLf


    不用第三方的行吗?关键词为MSOUC.EXE

TOP

本帖最后由 suchost 于 2015-10-27 18:10 编辑

回复 3# pcl_test


    版主很棒哦,但能根据关键词来提取关键词所在行及相应的[]吗?比如关键词为MSOUC,得到的结果为:
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ZONE_ELEVATION]
"MSOUC.EXE"=dword:00000001
这样呢?

TOP

本帖最后由 pcl_test 于 2015-10-27 18:28 编辑

回复 5# suchost
  1. m[i].replace(/(\[)([^\]]+?\]\r?\n)[\s\S]*?(.*?MSOUC\.EXE.*)/,'$1-$2$3')
复制代码

TOP

纯P
  1. @echo off & setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in (1.txt) do (
  3.     set "s=%%i"
  4.     if "!s:~0,1!!s:~-1!" == "[]" (
  5.         set "s1=!s:[=[-!"
  6.     ) else (
  7.         if not "!s:"MSOUC.EXE"=!" == "!s!" echo;!s1!&echo;!s!
  8.     )
  9. )
  10. pause
复制代码
1

评分人数

    • suchost: 乐于助人,谢谢技术 + 1

TOP

不太理解为什么要从这个文件取。
直接从注册表直接读不行?

TOP

回复 8# 依山居


  直接读取更好,请赐教啊!

TOP

回复 6# pcl_test


    这行代码怎么用呀?

TOP

本帖最后由 suchost 于 2015-10-27 20:52 编辑

回复 7# WHY


    怎么输出到文件呀?还有一行没显示出来

TOP

回复 11# suchost


@echo off & setlocal enabledelayedexpansion
(for /f "delims=" %%i in (1.txt) do (
    set "s=%%i"
    if "!s:~0,1!!s:~-1!" == "[]" (
        set "s1=!s:[=[-!"
    ) else (
        if not "!s:"MSOUC.EXE"=!" == "!s!" echo;!s1!&echo;!s!
    )
))>2.txt
pause
1

评分人数

我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 10# suchost
  1. //&cls&cscript -nologo -e:jscript "%~f0"<"1.txt"&pause&exit
  2. var m=WScript.StdIn.ReadAll().match(/\[[^\]]+?\]\r?\n[^\[]*?MSOUC\.EXE[^\[]*/g)
  3. for (var i=0; i<m.length; i++) WSH.echo(m[i].replace(/(\[)([^\]]+?\]\r?\n)[\s\S]*?(.*?MSOUC\.EXE.*)/,'$1-$2$3'));
复制代码
整段代码保存为 test.bat 双击执行
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 9# suchost


    你的 1.txt 是执行哪个命令得到的结果?发出来看看吧
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

我只想问楼主真的了解注册表吗?
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

返回列表