标题: 请问:如何用批处理替换文件里的字符。
[打印本页]
作者: lianjiang2004
时间: 2006-12-17 09:52
标题: 请问:如何用批处理替换文件里的字符。
请问:如何用批处理替换文件里的字符。
就是想用批处理把menu.lst里的password那行替换成md5.txt里的字符。
文件md5.txt里只有一行:
----------
password --md5 $1$/$xt8NeSA6RgbRCGBqjoL8K.
文件menu.lst的内容如下:
----------------
color white/green yellow/green
timeout 10
default 0
fontfile (hd0,4)/grub/fonts
splashimage (hd0,4)/grub/bg.xpm.gz
#为Grub以MD5加密方式设置密码
password --md5 $1$4$b2m8/JQITYFtj7hf9w3iW/
title 安装Grub_v0.95到MBR,慎用! [先按p,输入密码]
lock
root (hd0,4)
setup (hd0)
reboot
作者: namejm
时间: 2006-12-17 10:15
试试下面的代码:
@echo off
cd.>test.txt
for /f "tokens=1* delims=:" %%i in ('findstr /n .* menu.lst') do (
set "var=%%j"
call :replace "%%j"
)
start test.txt
goto :eof
:replace
set str=%1
set "str=%str:~1,-1%"
if /i "%str:~0,8%"=="password" (
for /f "delims=" %%i in (md5.txt) do set "str=%%i"
)
>>test.txt echo.%str%
goto :eof
作者: lianjiang2004
时间: 2006-12-17 10:25
试了一下可以,谢谢了,我再好好研究一下这段代码。
作者: xingsys
时间: 2007-2-14 09:42
高,真是,请问一下版主,在以下menu.lst文件中,怎样用批处理制作为提示用户输入,然后把password=123中的123替换为用户的输入字符呢呢
文件menu.lst的内容如下:
----------------
color white/green yellow/green
timeout 10
default 0
fontfile (hd0,4)/grub/fonts
splashimage (hd0,4)/grub/bg.xpm.gz
password=123
title 安装Grub_v0.95到MBR,慎用! [先按p,输入密码]
lock
root (hd0,4)
setup (hd0)
reboot
作者: slore
时间: 2007-2-14 10:55
@echo off
echo ---------------->menu.lst
echo color white/green yellow/green>>menu.lst
echo timeout 10 >>menu.lst
echo default 0 >>menu.lst
echo.>>menu.lst
echo fontfile (hd0,4)/grub/fonts>>menu.lst
echo echo splashimage (hd0,4)/grub/bg.xpm.gz>>menu.lst
set /p pwd=请输入密码:
echo password=%pwd%>>menu.lst
echo title 安装Grub_v0.95到MBR,慎用! [先按p,输入密码]>>menu.lst
echo lock>>menu.lst
echo root (hd0,4)>>menu.lst
echo setup (hd0)>>menu.lst
echo reboot >>menu.lst
作者: xingsys
时间: 2007-2-14 11:21
万分感谢,唉,我怎么没想到了,谢谢了