18/03/17 21:16:57.69 Eknm4yJC.net
@echo off
set n0=0
set n1=0
set n2=0
set file="xxx.txt"
set newfile="new.txt"
set word=xxx
type nul>new.txt
for /f "tokens=1* delims=:" %%i in ('findstr /n "." %file%') do set n0=%%i
for /f "tokens=1* delims=:" %%i in ('findstr /n /c:"%word%" %file%') do set n1=%%i
for /f "tokens=1* delims=:" %%i in ('findstr /n /c:"-- %word%" %file%') do set n2=%%i
if %n0% equ %n1% if %n1% neq %n2% goto :eof
if %n0% equ %n2% (call :del-line %n2%) else (copy /y %file% %newfile%>nul)
call :add-line
move /y %newfile% %file%>nul
goto :eof
:del-line
for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" %file%') do if %%i neq %1 echo;%%j>>%newfile%
goto :eof
:add-line
echo;%word%>>%newfile%
goto :eof