中国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-13 22:20
47,812 topics / 349,916 posts / today 0 new / 48,268 members
论坛回收站 » [10QB Bounty] Asking everyone
Printable Version  9,908 / 6
Floor1 adslcool Posted 2010-11-18 16:11
新手上路 Posts 10 Credits 10
Asking everyone, how to use batch processing to call a random line from a text and define variables respectively?

The text content is like:
——————————
WKS001 1 abcdefg
WKS002 2 abcdefg
WKS003 3 abcdefg
WKS004 4 abcdefg
WKS005 5 abcdefg
WKS006 6 abcdefg
WKS006 6 abcdefg
...
——————————
In this way, the number of lines is not fixed, and each line has 3 segments of characters separated by spaces. It is required to randomly调入a certain line in batch processing, and then define the 3 segments of characters of that line as variables a b c

After debugging, I will recharge 10 Q coins to the author as a reward, thank you everyone

[ Last edited by adslcool on 2010-11-18 at 16:15 ]
Floor2 adslcool Posted 2010-11-18 16:12
新手上路 Posts 10 Credits 10
Floor3 523066680 Posted 2010-11-18 17:08
银牌会员 Posts 1,133 Credits 2,361
This Q coin seems not difficult to get... Is the above bid accepted?
Floor4 wewebb Posted 2010-11-18 18:13
初级用户 Posts 53 Credits 66


[ Last edited by wewebb on 2010-11-18 at 18:30 ]
Floor5 wewebb Posted 2010-11-18 18:15
初级用户 Posts 53 Credits 66


[ Last edited by wewebb on 2010-11-18 at 18:29 ]
Floor6 wewebb Posted 2010-11-18 18:47
初级用户 Posts 53 Credits 66
```
::If the file content is all in the same format (no extra information lines), and the numbers in each line are of variable numbers.

@echo off & Title Variable Random Definition
Setlocal EnableDelayedExpansion

::Find out how many lines are in the file
For /f "delims=" %%a in (File.txt) do set /a N+=1

Echo File.txt has!N! lines!

::Set random line number
set /a Line=%Random% %%!N! +1

For /f "tokens=1-3" %%a in (File.txt) do (
set /a num+=1
if!num! ==!Line! (set "One=%%a" & set "Two=%%b" & set "Thr=%%c")
)
echo %One%
echo %Two%
echo %Thr%
Endlocal
Pause
```

[ Last edited by wewebb on 2010-11-18 at 18:49 ]
Floor7 adslcool Posted 2010-11-18 22:23
新手上路 Posts 10 Credits 10
Thanks to everyone, I'll test it first, the above expert's
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023