@ECHO OFF
SETLOCAL
SET "prevline="
(
FOR /f "delims=" %%a IN (q19992107.txt) DO (
SET line=%%a
CALL :check
)
SET "line="
CALL :check
)>newfile.txt
TYPE newfile.txt
GOTO :EOF
:check
IF NOT DEFINED prevline GOTO done
SET aftertc=%prevline:*T/C=%
IF "%aftertc%"=="%prevline%" SET prevline=%prevline:~-2%%line%&GOTO :eof
SET bothline=%prevline%%line%
SET aftertc=%bothline:*T/C=%
SET aftertc=%aftertc:~0,15%
ECHO %aftertc%
:done
SET prevline=%line%
GOTO :eof
批处理不是一个理想的工具 - 但上面可能会奏效。
本质上,它保留两行,prevline
并且line
.
如果目标字符串不包含在上一行中,则将上一行的最后 2 个字符添加到当前行,并将结果用作上一行。
否则,将两条线连接起来,处理掉在 Then lop off the tail 之前的那个 pasrt T/C
- 为了测试方便,我将尾部限制为 15 个字符。然后像以前一样使用当前行。
使用最后 2 个字符的原因是如果序列被拆分为多行,则包含上一行的T
or 。T/
T/C
这是我使用的测试文件q19992107.txt
this is skipped
this contains T/C in line
no contents
skip this
this is irrelevant
split on / in T/
C was 1 split
this is irrelevant
split on / in T
/C was 2 split
there IS T/C
at the end of the previous line
and then there is T/C in the last
结果在newfile.txt
in lineno cont
was 1 splitthi
was 2 splitthe
at the end of t
in the last