gpt4 book ai didi

windows - 获取文本文件中两个单词之间的文本

转载 作者:可可西里 更新时间:2023-11-01 11:25:56 26 4
gpt4 key购买 nike

为简洁起见,我有一个如下所示的文本文件(在 Windows 中):

Blah Blah Blah Blah
Blah Blah Blah 2016
START-OF-FILE
ABC
ABCDE Blah Blah Blah
Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah
END-OF-FILE
Blah Blah Blah
Blah Blah Blah

我只想要 START-OF-FILE 和 END-OF-FILE 之间的文本

ABC
ABCDE Blah Blah Blah
Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah

我尝试使用 Findstr,但效果不佳。有人可以帮忙吗?

这是我目前所拥有的:

@echo off
setlocal enabledelayedexpansion

set quote=

for /f "tokens=*" %%a in (infile.txt) do (
set str=%%a
set str=!str:"=:!

if not "!str!"=="!str::=!" (
if defined quote (
set quote=
for %%b in (^"%%a) do set str=%%~b
if not "!str!"==START-OF-FILE if not "!str: =!"==END-OF-FILE echo !str! >> outfile.txt
) else (
set quote=1
for %%b in (%%a^") do set str=%%~b
)
)

if defined quote (
if not "!str!"==START-OF-FILE if not "!str: =!"==END-OF-FILE echo !str! >> outfile.txt
)
)

这是结果:

2016" 
START-OF-FILE
ABC
ABCDE Blah Blah Blah
Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah
END-OF-FILE
Blah Blah Blah

我需要不包含 2016"、START-OF-FILE 、END-OF-FILE 和 END-OF-FILE (Blah Blah Blah) 之后的行

最佳答案

@echo off
setlocal EnableDelayedExpansion

set "skip="
for /F "delims=:" %%a in ('findstr /N "START-OF-FILE END-OF-FILE" input.txt') do (
if not defined skip (
set "skip=%%a"
) else (
set /A "lines=%%a-skip-1"
)
)
(for /F "skip=%skip% delims=" %%a in (input.txt) do (
echo %%a
set /A lines-=1
if !lines! equ 0 goto break
)) > output.txt
:break

关于windows - 获取文本文件中两个单词之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36416492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com