0

I have a text file as below:

This is a sample file
some dummy text 
some dummy text
some dummy text
I don't know how many times this some dummy text above me is repeated
I need only the lines starting from here SOME IMP TEXT
SOME IMP TEXT
SOME IMP TEXT
I don't know how many times this SOME IMP TEXT above and below me is repeated
SOME IMP TEXT
I need it till I find this line SOME IMP TEXT
some dummy text
some dummy text
I don't know how many times this some dummy text above me is repeated

I need a file which has only the lines from "I need only the lines starting from here SOME IMP TEXT" till the find "I need text till I find this line SOME IMP TEXT" (Both the bold lines inclusive). Nothing but I need below:

I need only the lines starting from here SOME IMP TEXT
SOME IMP TEXT
SOME IMP TEXT
I don't know how many times this SOME IMP TEXT above and below me is repeated
SOME IMP TEXT
I need it till I find this line SOME IMP TEXT
Joshi
  • 573
  • 3
  • 11
  • 24

1 Answers1

1

Check the tailhead.bat - it can to show a file content from certain line to a another line by number.If you have the tailHead.bat you can:

@echo off
::==========================
:: 
set file=text.txt
set "line1=I need only the lines starting from here SOME IMP TEXT"
set "line2=I need it till I find this line SOME IMP TEXT"
::========================
for /f "tokens=1 delims=:" %%a in ('findstr /n /c:"%line1%" "%file%"') do set "l1=%%a"
for /f "tokens=1 delims=:" %%a in ('findstr /n /c:"%line2%" "%file%"') do set "l2=%%a"

::echo %l1%
::echo %l2%

tailhead.bat -file=text.txt -begin=%l1% -end=%l2%

this will include the lines. if you want to exclude them you can increase the begin line and decrease the end line with set /a

npocmaka
  • 55,367
  • 18
  • 148
  • 187