Searching a txt file for a line and deleting the subsequent 13 lines in a batch file

I have some txt files that I need a batch file to search for a specific line and then delete that line and the subsequent 13 lines from the txt file.

and example of the txt file is:

<section1>
line1
line2
line3

<section2>
line1
line2
line3
line4
line5

<section3>
line1
line2
line3
line4
line5
line6
line7
line8

etc.

The line i would need to search for is <section2> and then delete the following:

<section2>
line1
line2
line3
line4
line5

So ending up with:

<section1>
line1
line2
line3

<section3>
line1
line2
line3
line4
line5
line6
line7
line8

etc.

I would also need to edit some lines after the other sections, for example edit line1 in <section3> to say editline1

So it would find the <section3> string and alter line 1 to appear as below

<section3>
editline1
line2
line3
line4
line5
line6
line7
line8

Thanks


ANSWERS:


@echo off
  set fnam="%~1"
  set outnam="%~dpn1.out"
  set search4="%~2"
  set section=.
  for /f "tokens=*" %%x in ('type %fnam%') do call :work %fnam% "%%x"
  MOVE /Y %outnam% %fnam%
goto :eof

:work
  set "line=%~2"
  if "%line:~0,1%%line:~-1%"=="<>" (
    if "%section%" neq "." echo.>> %outnam%
    set "section=^%line:~,-1%^>"
    set "line=^%line:~,-1%^>"
  )
  if NOT "%section:~1,-2%>"==%search4% echo %line%>> %outnam%

Call it like this:

section filename.txt "<section2>"


 MORE:


 ? Batch for insert/replace in a txt file in a fixed position
 ? Batch Script - Find and replace text in multiple files in a directory
 ? Find and replace line starts with specific value in text file via windows batch file
 ? Remove folders from txt file in windows cmd
 ? replacing line in txt file AFTER specific line
 ? How to concatenate 2 .csv files in 1 .csv file with multiple sheets using Batch commands
 ? How to remove strings from a text file using batch script?
 ? How to remove strings from a text file using batch script?
 ? How to remove strings from a text file using batch script?
 ? How do I check that a parameter is defined when calling a batch file?