两种要求均能达成...
setlocal enabledelayedexpansion
set n=0
(for /f "usebackq tokens=* delims= " %%s in ("a.txt") do (
set z=%%s
if "!z:~-1!" equ ">" (set n=1)
if "!z:~,4!" equ "执行时间" (
if !n! equ 0 (echo,!ls!)&(echo,%%s)
set "n=0"
)
set ls=%%s
))>"a.new.txt"
剔除了首尾空格 再试...
setlocal enabledelayedexpansion
set n=0
(for /f "usebackq tokens=* delims= " %%s in ("a.txt") do (
set z=%%s & set "z=!z: =!"
if "!z:~-1!" equ ">" (set n=1)
if "!z:~,4!" equ "执行时间" (
if !n! equ 0 (echo,!ls!)&(echo,%%s)
set "n=0"
)
set ls=%%s
)) >"a.new.txt"