@ECHO OFF
SETLOCAL
SET "sourcedir=U:sourcedir"
SET "destdir=U:destdir"
SET "filename1=%sourcedir%q40953616.txt"
SET "outfile=%destdir%outfile.txt"
SET "part1="
(
FOR /f "usebackqdelims=" %%i IN ("%filename1%") DO (
ECHO %%i|FIND "$" >NUL
IF ERRORLEVEL 1 (
REM $ not found - set part1 on first such line
IF NOT DEFINED part1 SET "part1=%%i"
) ELSE (
REM $ found - see whether at start or not
FOR /f "tokens=1*delims=$" %%a IN ("%%i") DO (
IF "%%b"=="" (
REM at start - combine and output and reset part1
CALL ECHO %%part1%% %%i
SET "part1="
) ELSE (
ECHO %%i
)
)
)
)
)>"%outfile%"
GOTO :EOF
You would need to change the settings of sourcedir
and destdir
to suit your circumstances.
I used a file named q40953616.txt
containing your data for my testing.
Produces the file defined as %outfile%
Scan each line of the file. If the line does not contain $
then save the first such line in part1
.
Otherwise, tokenise the line. If there is only 1 token, then the $
is at the start of the line, so it needs to be output combined with part1
Otherwise, just regurgitate the line.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…