中国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 10:29
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How can I use batch processing to calculate how many lines there are in a text file?
Printable Version  1,016 / 14
Floor1 theoldman Posted 2007-02-07 03:09
初级用户 Posts 16 Credits 39
How can I use batch processing to calculate how many lines there are in a text file? Then use that total line count to generate a random number and display a random line.

How exactly should I write the statement...
Floor2 ccwan Posted 2007-02-07 03:35
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Using findstr /n will tell you how many lines a file has. For details, type findstr /? at the command line to check.
To see how many lines are in the file test.txt, if you use a for statement, you can do it like this:

Floor3 namejm Posted 2007-02-07 04:16
荣誉版主 Posts 1,737 Credits 5,226 From 成都
  There was an error when merging; the OP is theoldman, not ccwan. Please forgive me, both of you, and everyone else please bear with it.
  ——————————————————————————
  The problem of misaligned post numbers has already been fixed by the admin. Everyone below, please make the corresponding changes to your reply content in time.

[ Last edited by namejm on 2007-2-6 at 04:11 PM ]
Floor4 ccwan Posted 2007-02-07 04:17
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Moderator, you're too modest. Actually, being the OP is pretty nice too, I just don't know whether the credits would accordingly go up by 4 points instead of 2?^_^

[ Last edited by ccwan on 2007-2-7 at 04:22 AM ]
Floor5 redtek Posted 2007-02-07 04:22
金牌会员 Posts 1,147 Credits 2,902
Floor6 ccwan Posted 2007-02-07 04:24
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Floor7 theoldman Posted 2007-02-07 04:30
初级用户 Posts 16 Credits 39
ccwan, if I want to display line 2, and this 2 is a variable, what exactly should the format be?
(Please forgive a newbie like me for asking such a simple question, I really couldn't find how to write it T_T~~)

[ Last edited by namejm on 2007-2-6 at 03:52 PM ]
Floor8 namejm Posted 2007-02-07 04:42
荣誉版主 Posts 1,737 Credits 5,226 From 成都
  The demo code is as follows:

  You can also use findstr /n, or display it through a counter.
Floor9 theoldman Posted 2007-02-07 04:50
初级用户 Posts 16 Credits 39
Moderator, what does this more do?
Floor10 zh159 Posted 2007-02-07 05:00
金牌会员 Posts 1,467 Credits 3,687
Use more/? and command /? more often in the CMD window.
Floor11 ccwan Posted 2007-02-07 05:01
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Just do as the poster above said.

[ Last edited by ccwan on 2007-2-7 at 05:06 AM ]
Floor12 zh159 Posted 2007-02-07 05:05
金牌会员 Posts 1,467 Credits 3,687
ccwan, your post on reply #4 is really hard on the eyes.
Floor13 ccwan Posted 2007-02-07 05:09
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Sorry everyone, the starting color and the ending color were set too light. You can select it to reverse it to white on black and it'll be clear.

Also, I suggest the OP read the basic command help more.
Floor14 vkill Posted 2007-02-07 05:24
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Floor15 theoldman Posted 2007-02-07 05:30
初级用户 Posts 16 Credits 39
Thanks to the helpful people above s ^_^

If I still can't understand it, I'll come back and bother everyone again.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023