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
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.
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%
Summary: I need to get from a file only the first line and to write it into other file-only using DOS commands.Till now I have managed to get the entire content of the file using a command like: FOR /F "usebac...
Summary: I have a requirment when in i need to get the last N number of line from a file and do a comparision.... can u guide me on how to get the last N lines from a file ...
Summary: Hi, I was wondering if it is possible to get the last line of a text file and save it to a variable? I found a script that gets the first line, but I have been unable to write one of my own. I could...