用bat修改ini配置文件指定内容

有两个ini文件 位于C:\1.bat和C:\2.bat 两个ini文件第15行是一样的参数
Location MAC=XXXXXX
需要用bat将两个文件修改为指定参数Location MAC=00:00:00:00:00:00
求各路大神帮忙!
路径要是绝对路径才行的 ,真实的ini文件在四层目录里面。所以要绝对路径

XXXX不是定量,是随机的

第1个回答  2013-06-04
@echo off&setlocal enabledelayedexpansion
del 1tmp.txt 2>nul
del 2tmp.txt 2>nul
for /f "delims=" %%1 in ('type "c:\1.ini"')do set strline=%%1&set newline=!strline:xxxxxx=00:00:00:00:00:00!&echo !

newline!>>1tmp.txt
for /f "delims=" %%1 in ('type "c:\2.ini"')do set strline=%%1&set newline=!strline:xxxxxx=00:00:00:00:00:00!&echo !

newline!>>2tmp.txt
del c:\1.ini
del c:\2.ini
move 1tmp.txt c:\1.ini
move 2tmp.txt c:\2.ini

参考以上酌情修改!
xxxxxx=00:00:00:00:00:00
xxxxxx是要修改的字符串
00:00:00:00:00:00 是修改后的字符串追问

亲,XXXX不是定量,是随机的,这行数值是的是第十五行

追答

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%1 in ('type "c:\1.ini"')do (set tmpstr=%%1&set tmp1=!tmpstr:~0,8!&(IF !tmp1!==Location (echo

Location MAC=00:00:00:00:00>>1tmp.txt))&(IF NOT !tmp1!==Location echo %%1>>1tmp.txt))
del c:\1.ini
move 1tmp.txt c:\1.ini

试试此例,此例假设 1.ini 文件中只有一行是以Location 开头的。
第二个文件同样处理。

第2个回答  2013-06-06
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%1 in ('type "c:\1.ini"')do (set tmpstr=%%1&set tmp1=!tmpstr:~0,8!&(IF !tmp1!==Location (echo

Location MAC=00:00:00:00:00>>1tmp.txt))&(IF NOT !tmp1!==Location echo %%1>>1tmp.txt))
del c:\1.ini
move 1tmp.txt c:\1.ini
相似回答