CODE: [Copy to clipboard]
@echo off&SetLocal ENABLEDELAYEDEXPANSION
:::::::::::ReadLine2.Bat::::::::::::::::::
if "%1"=="" (goto --help) else (set file=%1)
if not exist %file% goto :eof
if "%2"=="" (
for /f "tokens=1* delims=:" %%a in ('findstr /n .* "%file%"') do echo/%%b
goto :eof
) else (
set args=%*
for %%a in (!args!) do (
if not "%%a"=="%1" (for /f "tokens=1* delims=:" %%b in ('findstr /n .* "%file%"') do (
if "%%b"=="%%a" echo/%%c)
)
)
)
goto :eof
:--help
echo/======================================
echo/本程序段需要带参数才能正常运行
echo/&echo/Usage:&echo/Call ReadLine2 ^<文件名^> ^<读取行号^>
echo/&echo/例如:Call ReadLine2 aa.txt 5 7 11 ,将读取aa.txt文件的第5,7,11行
echo/&echo/如果^<读取行号^>没有指定,将读取整个文件的内容
echo/======================================
goto :eof