続き。tail コマンドの完成版。+ オプションもつけたが、単に more の機能を使っているだけ。
@echo off setlocal set MORE= if not defined LINE set LINE=20 set "OPT=%~1" if not defined OPT goto pipe if "%OPT:~0,1%"=="/" echo>&2 コマンドの構文が誤っています&exit /b 1 set OPTLINE=0 set /a "OPTLINE=%~1" 2>NUL >NUL if "%OPT:~0,1%"=="+" if %OPTLINE% geq 0 set /a L=OPTLINE&shift /1&goto plus if "%OPT:~0,1%"=="+" echo>&2 コマンドの構文が誤っています&exit /b 1 if "%OPT:~0,1%"=="-" if %OPTLINE% lss 0 set /a LINE=-OPTLINE&shift /1 if "%~1"=="" goto pipe for /f %%N in ('find /c /v "" ^< %1') do set /a L=%%N-LINE :plus if %L% lss 0 set L=0 more +%L% %1 goto :eof :pipe set TEMPFILE="%TEMP:"=%\$$$%TIME::=.%.TMP" set I=-%LINE% set J=0 for /f "delims=" %%A in ('more') do ( set /a J+=1, I+=1 echo.%%A>%TEMPFILE% call :setsub SAVE%%J%% SAVE%%I%% ) del %TEMPFILE% 2>NUL set /a I+=1 if %I% leq 0 set I=1 setlocal enabledelayedexpansion for /l %%K in (%I%,1,%J%) do echo.!SAVE%%K! goto :eof :setsub set /p %1=< %TEMPFILE% set %2=