Solved Multiple text file need to remove multiple line

April 30, 2019 at 02:51:03
Specs: Windows 7
Input:-

abcde1
[LDDIA:1456:**************************************************
*****************************************************************
**************************(multiple line here)******************
*****************************************************************
*******************************************]
abcde2
abcde3


Result:-

abcde1
abcde2
abcde3

Removed line starting with "[LDDIA:" end with "]"

@echo off
for /r %%a in (*.txt) do (
   echo processing "%%a"
   type "%%a"|findstr /v /i /l /c:"[LDDIA:" >"%%a.tmp"
   move "%%a.tmp" "%%a" >nul
)

Can anyone help me with the batch file?

Thanks
Pugazh

message edited by Pugazh


See More: Multiple text file need to remove multiple line

Reply ↓  Report •

#1
May 1, 2019 at 07:29:33
✔ Best Answer
try test.bat:

@echo off&setlocal enabledelayedexpansion
:dirloop
for /f %%a in ('dir/b/A-D ^| findstr ".txt"') do (
	set start=
	set end=
	set "filename=%%a"
	call :findstartofcolumn "%%a"
	call :findendofcolumn "%%a"
	call :overwritefile "%%a"
)
:done
echo DONE^^!
pause>nul
exit/b
:findstartofcolumn
echo Processing %~1
for /f "tokens=1* delims=" %%a in ('findstr /B /N "[LDDIA:1456:" "%~1"') do (
	for /f "tokens=1 delims=:" %%A in ("%%a") do (
		set "start=%%A"
		exit/b
	)
)
exit/b
:findendofcolumn
if "!start!"=="" exit/b
for /f "tokens=1* delims=" %%a in ('findstr /E /N "]" "%~1"') do (
	for /f "tokens=1 delims=:" %%A in ("%%a") do (
		set "end=%%A"
		exit/b
	)
)
exit/b
:overwritefile
if "!start!"=="" exit/b
if "!end!"=="" exit/b
for /f "tokens=* delims=" %%a in ('find /V /N "" %~1') do (
	set "temp1=%%a"
	call :echotofile "!filename!"
)
ren "!filename!" "!filename:~0,-4!.bak"
ren "!filename!.renamepls" "!filename!"
exit/b
:echotofile
if "%temp1:~-4%"==".TXT" exit/b
if %temp1:~1,1% LSS !start! echo !temp1:~3! >> "%~1.renamepls"
if %temp1:~1,1% GTR !end! echo !temp1:~3! >> "%~1.renamepls"
exit/b

i5-6600K[delid]@4.9GHz/4.4GHz cache@1.504v | 2x4GB Crucial-DDR4-2400CL17@CL12-15-15-28 1T 3000MHz@1.45v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.0v/2250MHz@1500MHz timings BiosModded


Reply ↓  Report •

#2
May 1, 2019 at 07:47:30
Perfect!!

Thank you :) @hidde663 :)

Thanks
Pugazh


Reply ↓  Report •
Related Solutions


Ask Question