中国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-09-23 13:28
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » [Closed]How to get the line number in a text?
Printable Version  5,988 / 4
Floor1 applecy Posted 2008-11-08 21:40
初级用户 Posts 78 Credits 168
RT.

There is a file adc.txt with content like:
aaa.exe
bbb.exe
ccc.exe
.....
zzzzz.exe

How to use random to get a random line number, then echo the content of that line.

Thanks to all the大虾 (experts) in advance.

[ Last edited by applecy on 2008-11-8 at 22:33 ]
Floor2 pusofalse Posted 2008-11-08 22:03
银牌会员 Posts 646 Credits 1,604
```@echo off
for /f "tokens=2 delims=:" %%a in ('find /c /v "" "abc.txt"') do set /a n=%random%%%%%a+1"
findstr /n .* abc.txt|findstr /b "%n%:"
pause>nul
```
Floor3 tireless Posted 2008-11-08 22:28
银牌会员 Posts 1,122 Credits 2,025
```@echo off
for /f %%a in (abc.txt) do set /a n+=1
set /a line=%random%%%%n%
for /f "delims=" %%b in ('more +%line% abc.txt') do echo %%b & goto out
:out
pause
```
Floor4 applecy Posted 2008-11-08 22:32
初级用户 Posts 78 Credits 168
Thanks to the brothers on the 2nd and 3rd floors.
Floor5 lk987655 Posted 2020-10-28 10:39
初级用户 Posts 76 Credits 185
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023