sed替换
@echo off
setlocal EnableDelayedExpansion
set dv=f
set bootdisk=c:
set "x=f:\boot\imgs\WePE_64_V1.2.iso"
rem 如果变量x里面含有/左斜杠,则不能被作为关键词,必须加上\转义字符
rem set "x2=WePE_64_V1.2.iso"
rem sed -e 's/\(.*\),/\1,,/'
for /f %%i in ('echo !x!^|sed -e "s/\(.*\)\\//"') do set x2=%%i
echo %x2%
set x=!x:%dv%:=!
set x=!x:\=\/!
echo !x!
rem 查找\boot\imgs\WePE_64_V1.2.iso所在行的上面3行,删除至chainloader所在的行:
set y=0
for /f %%i in ('sed -n "/%x%/=" "%bootdisk%\menu.lst"') do set /a y=%%i-3
if y gtr 0 (
echo %y%
sed -i "%y%,/chainloader/d" "%bootdisk%\menu.lst"
)
rem 查找第二个title的行的行号,增加启动菜单:
set y=0
for /f %%i in ('sed -n "/title/=" "%bootdisk%\menu.lst" ^|sed -n "2p"') do set /a y=%%i
if y gtr 0 (
echo %y%
sed -e "%y%i\title WINPE (%x2%)\@@find --ignore-floppies --ignore-cd --set-root !x!\@@map --mem --top !x! (0xff)\@@map --e820cycles=-1\@@map --hook\@@chainloader (0xff)@@" -i "%bootdisk%\menu.lst"
sed -i "s/@@/\r\n/g" "%bootdisk%\menu.lst"
)
start "1" "%bootdisk%\menu.lst"
pause
