:: tail.bat File Num [/N|/E|/C|/P|/S|/Tn]...
::
:: Prints the last Num lines of text file File.
::
:: The output will pause after filling the screen unless the /N option
:: is specified
::
:: The standard MORE options /E /C /P /S /Tn can be specified.
:: See MORE /? for more information
::
:: Source: dbenham | 02/12/2012
:: http://stackoverflow.com/a/9251975
::
::
:: Mods: Alex V | 08/17/2016
::
:: Usage: tail.bat C:\foo.bar 10 /N
:::::::::::::::::::::::::::::::::::::::
@echo OFF
setlocal
:: Variables ::::::::::::::::::::::::::
set "default_lines_to_display=" rem :: Will only set if none passed in
:::::::::::::::::::::::::::::::::::::::
:: Defaults :::::::::::::::::::::::::::
set "file=%~1"
set "cnt=%~2"
shift /1
shift /1
set "options="
set "noPause="
:: Parse Parameters :::::::::::::::::::
:parseOptions
if "%~1" neq "" (
if /i "%~1" equ "/N" (set noPause=^| findstr "^") else set options=%options% %~1
shift /1
goto :parseOptions
)
:: Get total lines ::::::::::::::::::::
if defined file (
if exist "%file%" (
for /f %%N in ('find /c /v "" ^<"%file%"') do set "skip=%%N"
) else (
echo ERROR: Unable to locate %file%
)
) else (
echo ERROR: Missing file parameter
echo.
goto :helpMe
)
:: Setting Default Line Count if NA :::
if not defined cnt (
if not defined default_lines_to_display (
set "cnt=0"
) else (
set /a "cnt+=%default_lines_to_display%"
)
)
:: Defining number of lines to display
if not defined skip set "skip=0"
set /a "skip-=%cnt%"
if %skip% lss 0 set skip=0
:: FINALLY - "more" "Tail" "MORE" :::::
more +%skip% %options% "%file%" %noPause%
goto :eof
:helpMe
echo USAGE: tail.bat filename [Lines] [/N^|/E^|/C^|/P^|/S^|/Tn]
echo Prints the last Num lines of text file File.
echo/
echo The output will pause after filling the screen unless the /N option
echo is specified
echo/
echo The standard MORE options /E /C /P /S /Tn can be specified.
echo See MORE /? for more information
echo/
echo Example:
echo tail.bat "dir to file\foo.bar" 50 /N
echo/
Comments
0 B
|👍
/👎