Sometime it need to access last n strings in text file, right? Of course you can use third party tools for this purpose (such as tail from Win 2k3 Resource Kit) but how about to create it by yourself? For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | @echo off
setlocal
if [%1] equ [] goto:help
(echo %1 | findstr /r /c:[0-9])>nul && if %errorlevel% neq 1 (
if exist %2 call:tail %2 %1
)
if exist %1 call:tail %1 10
goto:eof
:tail
for /f "tokens=*" %%i in ("%~1") do (
for /f "tokens=3 delims=:" %%j in ('find /c /v "" "%%~fni"') do (
set /a "str=%%j - %2"
)
)
more +%str% %1
endlocal
exit /b
:help
echo.%~n0 v1.01 - reads last N strings in text files
echo.
echo.Usage: %~n0 [number] ^<text file name^>
echo.e.g.: %~n0 events.log - show last ten strings
echo.e.g.: %~n0 3 events.log - print only three last strings
exit /b 1
|
Tags: tail