中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-03 23:59
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Split a file under DOS
Printable Version  1,045 / 11
Floor1 lxq73061 Posted 2007-04-01 05:29
初级用户 Posts 17 Credits 38
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?
Floor2 bjsh Posted 2007-04-01 05:58
银牌会员 Posts 621 Credits 2,000
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
Floor3 wuwuwuming Posted 2007-04-01 09:57
初级用户 Posts 18 Credits 37
Awesome~~~~~~~~
Floor4 lxq73061 Posted 2007-04-02 23:10
初级用户 Posts 17 Credits 38
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.
Floor5 NaturalJ0 Posted 2007-04-03 00:37
银牌会员 Posts 533 Credits 1,181
You need to use delayed variable expansion
Floor6 lxq73061 Posted 2007-04-04 06:27
初级用户 Posts 17 Credits 38
What does that mean?
Floor7 bjsh Posted 2007-04-04 06:45
银牌会员 Posts 621 Credits 2,000
Upload your file as an attachment
Floor8 lxq73061 Posted 2007-04-04 07:06
初级用户 Posts 17 Credits 38
The numbers are in the attachment

Attachments
号码列表.rar (48.07 KiB)
Floor9 dikex Posted 2007-04-04 07:17
高级用户 Posts 366 Credits 788
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.

Floor10 beijingju Posted 2007-04-04 09:13
初级用户 Posts 11 Credits 26
All experts here, I came because of the reputation and learned something.
Floor11 lxq73061 Posted 2007-04-05 00:07
初级用户 Posts 17 Credits 38
It's already OK, but cmd seems to use a lot of CPU. Is there any good solution?
Floor12 dikex Posted 2007-04-05 01:21
高级用户 Posts 366 Credits 788
Because the amount of information you need to process is too large, it will use quite a bit of CPU resources
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023