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-04 02:12
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Split a file under DOS View 1,047 Replies 11
Original Poster Posted 2007-04-01 05:29 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 38
Posts 17
Joined 2006-10-12 01:25
19-year member
UID 65383
Status Offline
I have a txt file with a total of ten thousand lines of numbers. Now I need to split it into multiple files, with 400 lines of numbers in each file. How should the DOS command be written?
Floor 2 Posted 2007-04-01 05:58 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Try this and see if it works



  1. @echo off
  2. set /a count=0
  3. set /a t=1
  4. for /f "delims=" %%a in (test.txt) do (
  5. set /a count+=1
  6. echo %%a >>%t%.txt
  7. if %count% geq 400 set /a count=0 && set /a t+=1
  8. )
Posted by BJSH: 2007-03-31 16:49
Floor 3 Posted 2007-04-01 09:57 ·  中国 广东 汕头 电信
初级用户
Credits 37
Posts 18
Joined 2007-04-01 08:57
19-year member
UID 83600
Gender Male
Status Offline
Awesome~~~~~~~~
Floor 4 Posted 2007-04-02 23:10 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 38
Posts 17
Joined 2006-10-12 01:25
19-year member
UID 65383
Status Offline
That's not right, why doesn't it work? It only generated one new 1.txt file, and it's even bigger than the original file.
Floor 5 Posted 2007-04-03 00:37 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
You need to use delayed variable expansion
Floor 6 Posted 2007-04-04 06:27 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 38
Posts 17
Joined 2006-10-12 01:25
19-year member
UID 65383
Status Offline
What does that mean?
Floor 7 Posted 2007-04-04 06:45 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Upload your file as an attachment
Floor 8 Posted 2007-04-04 07:06 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 38
Posts 17
Joined 2006-10-12 01:25
19-year member
UID 65383
Status Offline
The numbers are in the attachment
Attachments
号码列表.rar (48.07 KiB, Downloads: 20)
Floor 9 Posted 2007-04-04 07:17 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
This thing seems to be more than 10K lines after all...
Forget it, it doesn't affect anything. I modified the code in reply #2 a bit. No delayed variables needed; I used the call method instead.

@echo off
set /a count=0
set /a t=1
for /f "delims=" %%a in (test.txt) do call :doit %%a
goto :eof

:doit
set /a count+=1
echo %1 >>%t%.txt
if %count% geq 400 set /a count=0 && set /a t+=1
Floor 10 Posted 2007-04-04 09:13 ·  中国 河北 石家庄 联通
初级用户
Credits 26
Posts 11
Joined 2007-04-04 08:34
19-year member
UID 83921
Gender Male
Status Offline
All experts here, I came because of the reputation and learned something.
Floor 11 Posted 2007-04-05 00:07 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 38
Posts 17
Joined 2006-10-12 01:25
19-year member
UID 65383
Status Offline
It's already OK, but cmd seems to use a lot of CPU. Is there any good solution?
Floor 12 Posted 2007-04-05 01:21 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
Because the amount of information you need to process is too large, it will use quite a bit of CPU resources
Forum Jump: