说明: 当前有一个只有1列的文本,用批处理把此文本按指定行数合并为一行
方法一:
@echo off
(for /f "delims=" %%a in (文件名.txt) do (
set /p=%%a <nul
set /a "n+=1, 1/(n%%2)" 2>nul || echo,
))>2.txt
type 2.txt
pause
方法二:
@echo off & setlocal ENABLEDELAYEDEXPANSION
set t=2
set l=0
echo Input source file name
set /p name=source name :
echo Input target file name
set /p tn= target name:
echo time data > %tn%.txt
(for /f %%a in (%name%.txt) do (
set /p=%%a <nul
set /a l +=1
set /a m=!l!%%!t!
if "!m!"=="0" echo.
)
) >> %tn%.txt
echo Display the txt
type %tn%.txt
pause
复制以上内容并保存为 .bat 文件,运行即可。