1.

Solve : How to run a batch file to Delete entries in *.ini?

Answer»

Dear ALL,

I am a new person

I have a question about DOS batch file COMMAND.

If I have a file (ABC.ini) and its format is shown as below:


[A_B_1]
master=LOC,123.123.123.123,00001
query=LOC,124.124.124.124,00001

[A_B_2]
master=LOC,123.123.123.123,00002
query=LOC,124.124.124.124,00002

Now, I want to write a batch file to delete all entries in the file (ABC.ini) for some KEYWORD.


such as KEYWORD is A_B_2, then

[A_B_2]
master=LOC,123.123.123.123,00002
query=LOC,124.124.124.124,00002

all of these are deleted.


Please give me some methods to deal with this case.

Thanks Thanks!!Use something like this:

Code: [Select]@echo off

rem Change file name and keyword here
SET FILE=abc.ini
set KEYWORD=[A_B_2]

set counter=0

if EXIST %FILE%.tmp del %FILE%.tmp

for /f "tokens=*" %%a in (%FILE%) do (
if not %%a==%KEYWORD% (
if !counter! equ 0 (
echo %%a >> %FILE%.tmp
) else (
set /a counter=!counter! - 1
)
) else (
rem Change number of lines to delete after keyword here
set counter=2
)
)

del %FILE%
move %FILE%.tmp %FILE%

Should work under W2K and WXP. Make SURE, command extensions and delayed expansion are enabled.

Cheers,
[glb]cs[/glb]



Discussion

No Comment Found