FINDSTR cannot solve this on its own.
Given your situation that you can simply delete all lines before the line that starts with [
, all you need is the following native batch script.
@echo off
setlocal
for /f "delims=:" %%N in ('findstr /n [ "file.txt"') do if not defined N set /a N=%%N-1
set "skip="
if %N% gtr 1 set "skip=skip=%N%"
(for /f "usebackq %skip% delims=" %%A in ("file.txt") do echo %%A) >"newFile.txt"
If you know that your file does not contain tabs, or if it is OK that tabs are converted to a string of spaces, then it is even easier:
@echo off
setlocal
for /f "delims=:" %%N in ('findstr /n [ "file.txt"') do if not defined N set /a N=%%N-1
more +%N% "file.txt" >"newFile.txt"
The solution is a one liner if you use REPL.BAT - a hybrid JScript/batch utility that performs regular expression search and replace on stdin and writes the result to std out. It is pure script that will run natively on any modern Windows machine from XP onward.
Assuming that [
only appears once, then:
type "file.txt" | repl "[^[]*\[" "[" m >"newFile.txt"
It is even simple to support multiple blocks between square brackets where the [
and/or ]
could be in the middle of a line:
type "file.txt" | repl "[^[]*(\[[\s\S]*?\])[^[]*" "$1\r\n" mx >"newFile.txt"