Solved Extract lines between specefic text

January 11, 2017 at 14:56:52
Specs: Windows 7
I have several text files that i want to batch process to extract the following information from each file.
I want to extract all lines of text after the word

"Daily Schedule :"

and ends with a ":"
In other words it looks like
bla bla bla

Daily Schedule:
bla bala bla bla bla bla
blabla ba bla tra cra:
abc dyr gryc cfd
uryhrods

Daily Schedule:
bla bala bla bla bla bla
blabla ba bla tra cra:

This appears several times in the text and I only want to extract into a seperate file all words starting with "Daily Schedule:" and ending with the ":" that appears in the like cra: in the example above.


See More: Extract lines between specefic text

Report •

#1
Report •

#2
January 12, 2017 at 22:34:00
✔ Best Answer
rem prototype only, not finalized:
@echo off & setlocaL enabledelayedexpansion
rem input is filename, outputs are filename_
set fn=%~n1
set c=0

for /f "tokens=1* delims=:" %%a in ('findstr /n /e "Daily Schedule:"^<%1') do (
>%fn%_!c! echo %%b
call :aa %%a
set /a c+=1
echo ---------------- next out to: %fn%_!c!
)
goto :eof

:aa
for /f "tokens=*" %%c in ('more +%1 %fn%') do (
rem two lines of debugging left in, just in case...
echo [%%c]
echo %fn%_%c% !c!__________________ %%c
>>%fn%_%c% echo %%c
echo %%c| findstr /e ":">nul&&goto :eof
)
goto :eof
::========= end: CAUTION: NO OVERWRITE-SAFETY IN PLACE:
make backup of work-area or run script in temp work-area till tested.


Report •
Related Solutions


Ask Question