Splicing adjacent odd and even lines of text content

Time:2021-1-20
Copy codeThe code is as follows:
@echo off
goto run

The problem is that there is a text file, and the contents are as follows
accident
n. Accident (factor)
across
Across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across
active
Active, agile, active; active
advertise
To announce; advertise; advertise
after
After; after
How can I put it in another file
Accident, accident, factor
Across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across across
Active, agile, active; active
To advertise for
After; after; after

The conventional solution is as follows
@echo off
:: code by jm 2006-9-21 [email protected]
set /a num=1
setlocal enabledelayedexpansion
for /f “tokens=*” %%i in (1.txt) do (
set /a num+=1
set /a mod=!num!%%2
if !mod! equ 1 (set var=%%i) else (set str=%%i)
if !mod! equ 1 echo !str! !var!
)
pause
goto :eof

The most concise and efficient solution:
:run
@echo off
:: code by 3742668 2006-9-21 [email protected]
setlocal ENABLEDELAYEDEXPANSION
for /f “delims=” %%i in (1.txt) do (
if “!str!” == “” ( set str=%%i
) else (
echo !str! %%i
set str=
)
)
pause

Recommended Today

JS function

1. Ordinary function Grammar: Function function name (){ Statement block } 2. Functions with parameters Grammar: Function function name (parameter list){ Statement block } 3. Function with return value Grammar: Function function name (parameter list){ Statement block; Return value; } Allow a variable to accept the return value after calling the function Var variable name […]