::如果每行中间的那个数字是序号的话,可以用 Findstr 随机找出。
@echo off & Title 变量随机定义
Setlocal EnableDelayedExpansion
::查找文件里的有效数据有多少行:
For /f %%a in ('findstr "^WKS" File.txt ') do (set /a N+=1)
Echo File.txt 文件共有 !N! 行有效数据!
::设置随机数,并用 Findstr 找出 行中间有对应数的那一行。
set /a Line=%Random% %% !N! +1
For /f "tokens=1-3" %%a in ('findstr " %Line% " File.txt ') do (
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:30 ]
::If the number in the middle of each line is the serial number, you can use Findstr to randomly find it.
@echo off & Title Variable Random Definition
Setlocal EnableDelayedExpansion
::Find out how many valid lines are in the file:
For /f %%a in ('findstr "^WKS" File.txt ') do (set /a N+=1)
Echo There are !N! lines of valid data in File.txt!
::Set random number and use Findstr to find the line with the corresponding number in the middle of the line.
set /a Line=%Random% %% !N! +1
For /f "tokens=1-3" %%a in ('findstr " %Line% " File.txt ') do (
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:30 ]