Batch to get lines between two strings in multiple text files in subfolders -


i have series of text files each named same in sub-folders of directory

ac.txt files have following structure :

---  text  ---  [lights]  ---  text  ---  [getenginedata]  ---  text  --- 

i want lines in between strings [lights] , [getenginedata] (including start [lights] , end [getenginedata] lines) in 1 single output file called lights.txt blank space in between coming each text file.

i coded following batch yet of no avail far :

@echo off  /r %%a in ('find /n "[lights]"^<(ac.txt) ') set /a start=%%a /r %%a in ('find /n "[generalenginedata]"^<(ac.txt) ') set /a end=%%a (     /r  %%a in ('find /n /v ""^<(ac.txt) ') (         if %%a geq %start% if %%f leq %end% echo(%%b     ) )>lights.txt 

here's way it. might not efficient seems job fine. code loops through subfolders , picks .txt files. parses each line of each file, marking beginning/end of each block using [lights] , [generalenginedata] tokens , outputs res.txt in same folder batch file stored.

@echo off  setlocal enabledelayedexpansion if exist res.txt del res.txt  set inblock=0 /r . %%a in (*.txt) (     set fname=%%a     /f "tokens=1* delims=]" %%b in ('type "!fname!" ^| find /n /v ""') (         if /i *%%c*==*[lights]* set inblock=1         if !inblock!==1 (             if *%%c*==** (echo.) else (echo %%c)             if /i *%%c*==*[getenginedata]* set inblock=0         )     )     echo.  ) >> res.txt set fname= set inblock= type res.txt 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -