Computing.Net > Forums > Programming > Get last line from a file

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.

Get last line from a file

Reply to Message Icon

Name: titto
Date: January 25, 2007 at 09:26:52 Pacific
OS: Win XP
CPU/Ram: 1 GB
Product: hp
Comment:

I'd like to write batch to read the last line (that in this case is a number) of a file log.txt and to assign this value to another variable.
I shoud repeat this operation every 10 seconds since the log.txt comes from a software application and updates every 5-10 seconds.

Thanks everybody..



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 25, 2007 at 10:08:45 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

:loop
for /f "tokens=* delims= " %%A in (log.txt) do (
set myvar=%%A
)
echo !myvar!
ping 0.0.1.1 -n 1 -w 10000 > nul
goto :loop



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: titto
Date: January 26, 2007 at 08:32:39 Pacific
Reply:

Hi M2Go,

it seems working perfectly!
than you very much!
Another question: do you know a way to print a string composed solely by a letter repeated n-times (with n a natural number to be defined)?
for example:
n=7 letter="q" -> string="qqqqqqq"
n=10 letter="x" -> string="xxxxxxxxxx"
thanks...


0

Response Number 3
Name: IVO
Date: January 26, 2007 at 13:18:29 Pacific
Reply:

@Echo Off
SetLocal EnableDelayedExpansion

Set Times=7
Set Char=k
Set String=

For /L %%A in (1,1,%Times%) Do Set String=!String!%Char%

Echo Times=%Times% - String=%String%



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


viewing my one written ap... C++ how to patch a file?



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Get last line from a file

Get first line from a file www.computing.net/answers/programming/get-first-line-from-a-file/14984.html

To get the last 10 lines of a file. www.computing.net/answers/programming/to-get-the-last-10-lines-of-a-file/20114.html

Get last line with batch file www.computing.net/answers/programming/get-last-line-with-batch-file/17019.html