[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]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"
先谢了!

给这个需求量身定做的:
http://www.bathome.net/thread-37861-1-1.html
  1. cscript -nologo context.js -iegoc -f /^\[/ 'msouc.exe' -t +0 Z:\a.txt
复制代码
  1. context.exe -iegoc -f /^\[/ 'msouc.exe' -t +0 Z:\a.txt
复制代码
  1. ncontext.exe -iegoc -f /^\[/ 'msouc.exe' -t +0 Z:\a.txt
复制代码
需要的话还可以用 --color 开关高亮显示
2

评分人数

    • apang: 路过来加分技术 + 1
    • 依山居: 楼主一定是买了VIP功能。技术 + 1

TOP

回复 21# pcl_test


再次测试,发现没错,感谢大家的热情帮助!

TOP

回复 20# suchost
对于秒还原我就不回什么了直接给你改变完的代码
  1. @echo off
  2. (echo Windows Registry Editor Version 5.00
  3. echo/)>"%~dp0\1_new.reg"
  4. (for /f "delims=[" %%i in ('type "%~dp0\1.txt"^|findstr/i "hkey_"') do (
  5. echo=[-%%i
  6. echo/
  7. ))>>"%~dp0\1_new.reg"
  8. pause
复制代码
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

本帖最后由 pcl_test 于 2015-10-27 21:23 编辑

回复 18# suchost

报什么错?肯定没改对,把你改的代码发出来,报错也截图出来

TOP

回复 19# /zhqsystem/zhq


    这个不用担心的,秒还原

TOP

回复 17# suchost r
如果不了解不要删除某个主项,这样会吧其他文件破坏,删除对应键值和关联即可[当这个主项全部为一个软件的注册表项时才可以全部删除],如果将主项全部删除会出现连锁反应或者未知的错误导致系统不能正常开机,最好保留原始注册表文件备用
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

回复 6# pcl_test


    执行报错

TOP

回复 15# /zhqsystem/zhq


    不了解

TOP

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

回复 14# Batcher


   手工导出,哈哈,一个有用的导出注册表代码:
  1. @set @n=0;/* & echo off & setlocal enabledelayedexpansion
  2. md "reg" 2>nul
  3. pushd "reg\"
  4. (for %%a in (HKLM HKCU HKCR HKU HKCC) do (
  5.         set "n="
  6.         for /f "delims=" %%b in ('reg query "%%a" /s /f "txt" /k') do (
  7.                 set /a n+=1
  8.                 reg export "%%b" %%a_!n!.reg
  9.         )
  10. )) 2>nul
  11. dir /b *.reg | cscript -nologo -e:jscript "%~0"
  12. start "" ".\"
  13. pause & exit/b & rem */
  14. fso = new ActiveXObject("Scripting.FileSystemObject");
  15. while (!WScript.StdIn.AtEndOfstream) {
  16.         file = WScript.StdIn.ReadLine();
  17.         f = fso.OpenTextFile(file, 1, false, -1);
  18.         txt= f.Readall();
  19.         f.Close();
  20.         txt= /[\s\S]*?^\[[\s\S]*?(?=^\[)/m.exec(txt + "\r\n[")[0];
  21.         fso.OpenTextFile(file, 2, true, -1).write(txt);
  22. }
复制代码
注意改txt

TOP

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

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

回复 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

回复 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

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

回复 7# WHY


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

TOP

返回列表