批处理 如何替换含有指定字符串的行中的指定内容

例如下述文本中(其中有很多内容),我想把所有含有0x00030001的行中的HKLM,"SYSTEM\替换为RegAdd,HKLM,0x3,"SYS\,并把这一行中的,0... 例如下述文本中(其中有很多内容),我想把所有含有 0x00030001 的行中的 HKLM,"SYSTEM\ 替换为 RegAdd, HKLM,0x3,"SYS\ ,并把这一行中的 ,0x00030001, 替换为 ,(一个逗号),其它行不变。这样的批处理请老师帮助,谢谢!
HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Pointer Class",0x00000002,"00335"
HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Pointer Port",\,0x00010001,"Scsi" HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Primary Disk",0x00030001,\
05,00,00,00,01,00,00,00,02,00,00,00,03,00,00,00,04,00,00,00,05,00,00,00
HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","SCSI CDROM Class",0x00030001,\
02,00,00,00,01,00,00,00,02,00,00,00
HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","SCSI Class",0x00030003,\
03,00,00,00,01,00,00,00,02,00,00,00,03,00,00,00
展开
 我来答
绝世流星雨
2014-07-23 · 超过18用户采纳过TA的回答
知道答主
回答量:49
采纳率:0%
帮助的人:43.8万
展开全部
  1、将建一个文件text.txt,存放你要替换的内容,如:

  HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Pointer Class",0x00000002,"00335"
  HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Pointer Port",\,0x00010001,"Scsi" HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Primary Disk",0x00030001,\
  05,00,00,00,01,00,00,00,02,00,00,00,03,00,00,00,04,00,00,00,05,00,00,00
  HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","SCSI CDROM Class",0x00030001,\
  02,00,00,00,01,00,00,00,02,00,00,00
  HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","SCSI Class",0x00030003,\
  03,00,00,00,01,00,00,00,02,00,00,00,03,00,00,00

  2、新建一个TestReplace.bat文件,内容如下:
  @echo off
  setlocal enabledelayedexpansion
  cls
  echo 正在处理,请稍候……
  if exist result.txt del /q result.txt
  for /f "delims=" %%i in (text.txt) do (
   set text=%%i
   set flag=
   for /f "delims=" %%a in ('echo !text! ^| findstr "0x00030001"') do (
   set str=%%a
   set str=!str:0x00030001=,!
   set str=!str:HKLM,"SYSTEM\=RegAdd, HKLM,0x3,"SYS\!
   echo !str!>>result.txt
   set flag=1
   )
   if not defined flag echo !text!>>result.txt
  )
  echo,&echo 处理完成.
  echo,&echo 按任意键退出.&pause>nul

  3、结果保存到result.txt,如下:
  HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","Pointer Class",0x00000002,"00335"
  RegAdd, HKLM,0x3,"SYS\CurrentControlSet\Control\GroupOrderList","Pointer Port",\,0x00010001,"Scsi" RegAdd, HKLM,0x3,"SYS\CurrentControlSet\Control\GroupOrderList","Primary Disk",,,\
  05,00,00,00,01,00,00,00,02,00,00,00,03,00,00,00,04,00,00,00,05,00,00,00
  RegAdd, HKLM,0x3,"SYS\CurrentControlSet\Control\GroupOrderList","SCSI CDROM Class",,,\
  02,00,00,00,01,00,00,00,02,00,00,00
  HKLM,"SYSTEM\CurrentControlSet\Control\GroupOrderList","SCSI Class",0x00030003,\
  03,00,00,00,01,00,00,00,02,00,00,00,03,00,00,00

  注:直接双击“TestReplase.bat”即可得到结果文件result.txt。
追问
谢谢! 好像不行,没有反应。
追答

text.txt与TestReplace.bat要在同一个目录哦。你用我上传的附件试试。

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式