Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to read the last 5 or 10 lines of text from my backup_log.txt file and output it to a file...so far it works but only prints the last line.
@echo off
for /f "tokens=*" %%a in (backup_log.txt) do set LastLine=%%a
echo %LastLine%I am new to the FOR statement. Any ideas?
Thank you,

Hi Stan,
This was submitted by IVO a couple weeks ago:
::***************************
@Echo Off:: COUNT.BAT Syntax: Count #_of_lines FileName Output_File
Echo.
If %2.==. Echo Missing source file & GoTo :EOF
If not exist %~f2 Echo File %~f2 not found & Goto :EOF
If %3.==. Echo Missing output destination & GoTo :EOF
Echo Extracting last %1 lines from %~f2 into %~f3If exist %~f3 Del %~f3
For /F "tokens=3 delims=:" %%A in ('Find /V /C "#~#" %~f2') Do Set RN=%%A
Set /A SN=%RN%-%1
If %SN% leq 0 Echo Too many lines [File contains %RN% lines] & GoTo :EOF
Echo Skipping %SN% lines from %RN%
For /F "tokens=* skip=%SN% delims=" %%A in (%~f2) Do Echo %%A>> %~f3
Set RN=
Set SN=
::*****************M2
If at first you don't succeed, you're about average.

![]() |
Using a non-Administrator...
|
Nt4 OldPC
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |