Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display text from .txt file in batch file

I'm scripting a big batch file.

It records the date to a log.txt file:

@echo off
echo %date%, %time% >> log.txt
echo Current date/time is %date%, %time%.
@pause
exit

It can record it several times, on several lines. Now what I want to do is that the batch file file shows the last recorded date/time from the log.txt file.

How?

like image 348
Deniz Zoeteman Avatar asked May 24 '09 10:05

Deniz Zoeteman


People also ask

What does @echo off mean in CMD?

echo off. When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: @echo off.


1 Answers

type log.txt

But that will give you the whole file. You could change it to:

echo %date%, %time% >> log.txt
echo %date%, %time% > log_last.txt
...
type log_last.txt

to get only the last one.

like image 110
viraptor Avatar answered Oct 04 '22 22:10

viraptor