I trying to make an small ping log to check when the IP isn't reachable but only issue is that all info goes down to the bottom of the file. Is it possible to print it to the top?
My script so far:
@ECHO OFF
:LOOPSTART
date /T>> PingLog.txt
time /T >> PingLog.txt
ping 192.168.0.2 -n 4 >> PingLog.txt
TIMEOUT 10
GOTO LOOPSTART
How to print to first line of txt file?
Moderator: DosItHelp
Re: How to print to first line of txt file?
For every line you'd need to do some complex manipulation, like:
Is this worth it?
Instead, I suggest that you consider using a Windows port of the Unix tail tool.
For example get tail.exe from UnxUtils.zip
Example of use:
will always show you the last 5 lines
Code: Select all
WriteLine > PingLog2.txt
type PingLog.txt >> PingLog2.txt
del PingLog.txt
ren PingLog2.txt PingLog2.txt
Instead, I suggest that you consider using a Windows port of the Unix tail tool.
For example get tail.exe from UnxUtils.zip
Example of use:
Code: Select all
tail -5 PingLog.txt
Re: How to print to first line of txt file?
Depending on the formatting of the your date/time stamps you could use the SORT command.