使用批处理从行中复制特定文本

Copy a specific text from lines using batch

我的输入文件是这样的:

text text
text text
text START_CHR line 1: text text text;
text START_CHR line 2: text text text;
text START_CHR line 3: text text text;
...
text text
eof

我需要将所有行复制到 START_CHR 和“;”之间的文件。

所需的输出文件:

START_CHR line 1: text text text;
START_CHR line 2: text text text;
START_CHR line 3: text text text;

   line 1: text text text
   line 2: text text text
   line 3: text text text

START_CHR和';'是行的分隔符。

不幸的是 findstr 'START_CHR' inFile.txt > outFile.txt 结果是:

text START_CHR line 1: text text text;
text START_CHR line 2: text text text;
text START_CHR line 3: text text text;

如何获得所需的输出文件?

干杯,安迪

@echo off
setlocal EnableDelayedExpansion

(for /F "delims=;" %%a in ('findstr "START_CHR" inFile.txt') do (
   set "line=%%a"
   echo !line:*START_CHR=!
)) > outFile.txt