bat,如何随机地显示一个文本文件的第N行
1个回答
2008-08-12
展开全部
@echo off
setlocal
REM %random:~0,n%的n为产生数字的最多位数
Set N=%random:~0,1%
:getfilename
Set /p file=请拖放一个文件到这里:
If not defined file Goto getfilename
If not exist %file% (Echo 错误:文件%file%无法找到。& Exit /b 1)
If "%N%" == "1" For /f "usebackq tokens=1,*" %%i In (%file%) Do (Echo 第%N%行:%%i %%j&endlocal & Exit /b 0)
Set /a skip=N-1
For /f "usebackq tokens=1,* skip=%skip%" %%i In (%file%) Do (Echo 第%N%行:%%i %%j&endlocal & Exit /b 0)
setlocal
REM %random:~0,n%的n为产生数字的最多位数
Set N=%random:~0,1%
:getfilename
Set /p file=请拖放一个文件到这里:
If not defined file Goto getfilename
If not exist %file% (Echo 错误:文件%file%无法找到。& Exit /b 1)
If "%N%" == "1" For /f "usebackq tokens=1,*" %%i In (%file%) Do (Echo 第%N%行:%%i %%j&endlocal & Exit /b 0)
Set /a skip=N-1
For /f "usebackq tokens=1,* skip=%skip%" %%i In (%file%) Do (Echo 第%N%行:%%i %%j&endlocal & Exit /b 0)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询