我想我理解了这个问题:给定 diflog.txt 中包含内容 Sumbitting Receipt 的某些行,如果它们还包含苹果或番茄,您想要提取所有这些行。此外,您想将苹果线一起输出,然后是番茄线。
这是我在没有实际 Windows 计算机的情况下可以做的最好的测试,您可以从这里对其进行微调,但这可能会有所帮助:
@echo OFF
setlocal enabledelayedexpansion
set apples=
set tomatos=
for /f "delims=" %%l in ('findstr /ilc:"Submitting Receipt" "diflog.txt"') do (
set line=%%l
for /f "eol=; tokens=1 delims=" %%s in ('echo !line! ^| findstr /ic:"apple"') do (
set new_apple=%%s
set apples=!apples!,!new_apple!
)
for /f "eol=; tokens=1 delims=" %%s in ('echo !line! ^| findstr /ic:"tomato"') do (
set new_tomato=%%s
set tomatos=!tomatos!,!new_tomato!
)
)
echo Apples:
for /f "eol=; tokens=1 delims=," %%a in ('echo !apples!') do (
set line_with_apple=@@a
echo !line_with_apple!
)
echo Tomatos:
for /f "eol=; tokens=1 delims=," %%t in ('echo !tomatos!') do (
set line_with_tomato=@@a
echo !line_with_tomato!
)