123
34
12
153
123
757
FileWithLineToComment.txt12
757
MyBatchFile.bat file.txt FileWithLineToComment.txt
123
34
//12
153
123
//757
Do more with
@echo off
setlocal EnableDelayedExpansion
REM Make sure required parms were supplied
if "%~1" EQU "" (
echo No data file specified to process
exit /b
)
if "%~2" EQU "" (
echo No comment file specified to process
exit /b
)
REM Get input file and comment file from command line parms
set Filename=%~1
set Comments=%~2
REM Define name for temporary file
set Outfile=%Temp%\%~nx1
REM Send changed file to tem file for now
(
REM Read each line of file
for /F "usebackq tokens=*" %%L in ("%Filename%") do (
REM Read each line from comment file
set MakeComment=N
for /F "usebackq tokens=*" %%C in ("%Comments%") do (
REM If this line is to be commented flag it
if /I "%%L" EQU "%%C" set MakeComment=Y
)
if "!MakeComment!" EQU "Y" (
echo.//%%L
) else (
echo.%%L
)
)
)>"%Outfile%"
if exist "%Outfile%" (
copy /Y "%Outfile%" "%Filename%" >NUL
del "%Outfile%" >NUL
)
~bp
Premium Content
You need an Expert Office subscription to comment.Start Free Trial