Board logo

标题: [文本处理] BAT如何提取txt文本中的指定字串的下面的两行内容? [打印本页]

作者: hp051247767    时间: 2013-10-31 09:08     标题: BAT如何提取txt文本中的指定字串的下面的两行内容?

本帖最后由 pcl_test 于 2017-6-14 12:27 编辑

有一optput.txt內容如下
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\{B43EA4C8-97EE-4580-B57C-D5802DA9B67E}]
"AuthorizedCDFPrefix"=""
"Comments"=""
"Contact"=""
"DisplayVersion"="12.1.2015.2015"
"HelpLink"=""
"HelpTelephone"=""
"InstallDate"="20131030"
"InstallLocation"="C:\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\12.1.2015.2015.105\\"
"URLInfoAbout"=""
"URLUpdateInfo"=""
"VersionMajor"=dword:0000000c
"VersionMinor"=dword:00000001
"WindowsInstaller"=dword:00000001
"Version"=dword:0c0107df
"Language"=dword:00000804
"DisplayName"="Symantec Endpoint Protection"
"DisplayIcon"="C:\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\12.1.2015.2015.105\\Bin\\SymCorpUI.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\{CC8BA866-16A7-4667-BA0C-C494A1E7B2BF}
"AuthorizedCDFPrefix"=""
"Comments"=""
想抓取"DisplayIcon"="C:\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\12.1.2015.2015.105\\Bin\\SymCorpUI.exe" 的下两行
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\{CC8BA866-16A7-4667-BA0C-C494A1E7B2BF}
并输出成get.txt     请问该如何做?
作者: foxJL    时间: 2013-10-31 10:22

你说的两行还包含一个空行?
实际所要的内容其实只有一行是吗
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\{CC8BA866-16A7-4667-BA0C-C494A1E7B2BF}
能不能简化一点以DisplayIcon或SymCorpUI.exe为关键词查找.
作者: hp051247767    时间: 2013-10-31 10:27

回复 2# foxJL
没错只要[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\{CC8BA866-16A7-4667-BA0C-C494A1E7B2BF}这行
没办法简化 因为是从Regedit 汇出的 需要作自动移除 所以需要{CC8BA866-16A7-4667-BA0C-C494A1E7B2BF}码
作者: foxJL    时间: 2013-10-31 11:03

  1. @echo off&setlocal enabledelayedexpansion
  2. set "s="DisplayIcon"="C:\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\12.1.2015.2015.105\\Bin\\SymCorpUI.exe""
  3. (for /f "delims=" %%i in (optput.txt) do (
  4.   if defined flag (echo,%%i&set "flag=")
  5.   if /i "%%i"=="!s!" set flag=1
  6. ))>>get.txt
复制代码

作者: hp051247767    时间: 2013-10-31 13:58

本帖最后由 hp051247767 于 2013-10-31 17:32 编辑

回复 4# foxJL
谢谢帮忙
作者: hp051247767    时间: 2013-10-31 17:32

回复 4# foxJL
那如果要抓這行請問要如何修改
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\{B43EA4C8-97EE-4580-B57C-D5802DA9B67E}]
作者: terse    时间: 2013-10-31 17:43

本帖最后由 terse 于 2013-10-31 17:46 编辑

回复 6# hp051247767
  1. set /p str=<optput.txt
  2. echo %str%
复制代码





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