China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 02:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Question about merging two documents, View 880 Replies 2
Original Poster Posted 2010-07-22 18:01 ·  中国 贵州 贵阳 南明区 电信
新手上路
Credits 2
Posts 2
Joined 2010-07-21 12:04
16-year member
UID 170897
Gender Male
Status Offline
I have a requirement: read the contents of a.txt three lines at a time, read one line from b.txt, then loop and write them into c.txt. How can this be done?
Floor 2 Posted 2010-07-23 15:26 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
18-year member
UID 96746
Gender Male
From 重庆
Status Offline
Assuming the line count ratio of files a and b is 3:1, and not considering special symbols:
@echo off
set p=-1
(for /f "delims=" %%i in (a.txt) do (
echo;%%i&set/a n+=1,m=n%%3
set/a test=1/m 2>nul||call :out
))>c.txt
exit

:out
set/a p+=1
if %p% equ 0 (for /f "delims=" %%j in (b.txt) do (echo;%%j&goto eof)) else (
for /f "skip=%p% delims=" %%j in (b.txt) do (echo;%%j&goto eof))
:eof
Floor 3 Posted 2010-08-02 12:10 ·  中国 贵州 贵阳 南明区 电信
新手上路
Credits 2
Posts 2
Joined 2010-07-21 12:04
16-year member
UID 170897
Gender Male
Status Offline
Thanks, it already meets the functional requirement
Forum Jump: