批处理 如何替换含有指定字符串的行中的指定内容
例如下述文本中(其中有很多内容),我想把所有含有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 展开
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 展开
1个回答
展开全部
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。
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要在同一个目录哦。你用我上传的附件试试。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询