本帖最后由 qixiaobin0715 于 2023-8-26 09:31 编辑
回复 41# 娜美
前面让你提供真实文本,样本不典型。修改了输出样式,这样看起来更一致:- @echo off
- (for /f "tokens=1* delims=>" %%i in (a.txt) do (
- set m=
- for /f %%x in ("%%j") do (
- if "%%x"=="企业" (
- set "str1=%%j"
- setlocal enabledelayedexpansion
- if not "!str1!"=="!str2!" (
- if defined n (
- echo,!Times!^> `退出
- echo,
- )
- )
- endlocal
- set n=0
- set "str2=%%j"
- ) else if "%%x"=="退出" (
- set m=1
- set n=
- )
- )
- if not "%%j"=="" (echo,%%i^>%%j) else echo,%%i
- if defined m echo,
- set "Times=%%i"
- ))>b.txt
- if %n% equ 0 echo,%Times%^> `退出>>b.txt
- (for /f "delims=:" %%i in ('findstr /r /n "`退出" b.txt') do echo,%%i)>AddedLines.txt
- pause
复制代码 再试试看看。 |