CMD.EXE batch script to display last 10 lines from a txt file

Hopefully this will save Joel's eyes :)

@echo OFF

:: Get the number of lines in the file
set LINES=0
for /f "delims==" %%I in (data.txt) do (
    set /a LINES=LINES+1
)

:: Print the last 10 lines (suggestion to use more courtsey of dmityugov)
set /a LINES=LINES-10
more +%LINES% < data.txt

This answer combines the best features of already existing answers, and adds a few twists.

The solution is a simple batch implementation of the tail command.

The first argument is the file name (possibly with path information - be sure to enclose in quotes if any portion of path contains spaces or other problematic characters).

The second argument is the number of lines to print.

Finally any of the standard MORE options can be appended: /E /C /P /S /Tn. (See MORE /? for more information).

Additionally the /N (no pause) option can be specified to cause the output to be printed continuosly without pausing.

The solution first uses FIND to quickly count the number of lines. The file is passed in via redirected input instead of using a filename argument in order to eliminate the printout of the filename in the FIND output.

The number of lines to skip is computed with SET /A, but then it resets the number to 0 if it is less than 0.

Finally uses MORE to print out the desired lines after skipping the unwanted lines. MORE will pause after each screen's worth of lines unless the output is redirected to a file or piped to another command. The /N option avoids the pauses by piping the MORE output to FINDSTR with a regex that matches all lines. It is important to use FINDSTR instead of FIND because FIND can truncate long lines.

:: 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
::
@echo OFF
setlocal
set file=%1
set "cnt=%~2"
shift /1
shift /1
set "options="
set "noPause="
:parseOptions
if "%~1" neq "" (
  if /i "%~1" equ "/N" (set noPause=^| findstr "^") else set options=%options% %~1
  shift /1
  goto :parseOptions
)
for /f %%N in ('find /c /v "" ^<%file%') do set skip=%%N
set /a "skip-=%cnt%"
if %skip% lss 0 set skip=0
more +%skip% %options% %file% %noPause%