Computing.Net > Forums > Windows NT > Batch File Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Help

Reply to Message Icon

Name: skito1_803
Date: April 28, 2005 at 09:40:02 Pacific
OS: NT 4
CPU/Ram: PIII 512 MB
Comment:

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,




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 28, 2005 at 13:06:02 Pacific
Reply:

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 %~f3

If 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.


0

Response Number 2
Name: skito1_803
Date: May 2, 2005 at 14:31:47 Pacific
Reply:

M2,

Wow, Days of hair pulling all solved by IVO. Thanks for the post.

Stan


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Windows NT Forum Home


Sponsored links

Ads by Google


Results for: Batch File Help

Win NT batch file Help please www.computing.net/answers/windows-nt/win-nt-batch-file-help-please/11724.html

Simple Batch File Help www.computing.net/answers/windows-nt/simple-batch-file-help/22792.html

Please Help! re: Batch Files www.computing.net/answers/windows-nt/please-help-re-batch-files/8255.html