delete lines with batch file, but ...

November 3, 2010 at 18:10:19
Specs: Windows Vista
Hi,

I want to use a dos batch file to parse a text file and delete all lines that contain a specific string. That's easy ... find /v does the job.

But, I don't want to delete the line that contains the first occurrence of the string.

Can you help??

TIA


See More: delete lines with batch file, but ...

Report •

#1
November 4, 2010 at 14:38:47
@echo off & setlocal EnableDelayedExpansion > FileOut.txt

set string=Here The String

(set flag=)
for /F "delims=" %%j in (FileIn.txt) do (
  set row=%%j
  if "!row:%string%=!"=="%%j" (
    echo.%%j>> FileOut.txt
  ) else (
    if not defined flag echo.%%j>> FileOut.txt
  )
  if not "!row:%string%=!"=="%%j" set flag=ON
)


Report •

#2
November 4, 2010 at 17:26:54
awesome!

thanks Ivo, that works perfectly!


Report •
Related Solutions


Ask Question