original file containing
;group 1
-epackage
.......
;group2
-epackage
.......
After replaced, it should looks like this
;group 1
-epackage
.......
;group2
;-epackage
Basically what I want is to comment out the second -epackage
I tried this following code
@echo off setlocal EnableDelayedExpansion
set "search=;group2" set "nextLine=;-epackage"
rem Get the line number of the search line for /F "delims=:" %%a in ('findstr /N /C:"%search%" Load_all.txt') do set /A "numLines=%%a-1"
rem Open a code block to read-input-file/create-output-file
< Load_all.txt (
rem Read the first line set /P "line="
rem Copy numLines-1 lines for /L %%i in (1,1,%numLines%) do set /P "line=!line!" & echo/
rem Replace the next line echo %nextLine%
rem Copy the rest of lines findstr "^"
) > output.txt
rem Replace input file with created output file move /Y output.txt Load_all.txt > NUL
However, the output I got is below
;group 1
-epackage
.......
;-epackage
-epackage
Which is not what I want....
Any idea to do the job?