1.

Solve : Show last line of text file?

Answer»

Hi

I have a batch file that performs a few actions on a binary file and then GENERATES a report (.txt). The last line on this report (.txt) list how many ERRORS encountered.

Is it possible for DOS to display the last line of TEXT from the reprot (.txt) to the users instead of having to open the report (.txt) file.

ThanksIf you used for to set the text file into variables, but only using a single variable.. the last line of the text file would be set as the result

for /f "tokens=1*" %%a in (yourtextfile.txt) do set a=%%a
THANKS for the code, I tied the line of code in a bat file but it does not seem to work.

My coding experience is in VB.NET so unfortunately I have little experience in DOS coding so I am unsure if the line of code that you supplied works on its own are requires more code.

I appreciate your help on this.

Thanks

he posted good solution look:

yourfile.txt
Code: [Select]AAA
BBB
VVV
yourbat.bat
Code: [Select]for /f "tokens=1*" %%a in (yourfile.txt) do set a=%%a

for /f "tokens=1*" %%a in (yourfile.txt) do set a=AAA

for /f "tokens=1*" %%a in (yourfile.txt) do set a=BBB

for /f "tokens=1*" %%a in (yourfile.txt) do set a=VVV

so at last a will ALWAYS be last line of fileSorry, I am not getting it.

Are you saying that the line of code previously supplied works and displays the last line of text because I am not seeing it, what I get is the first word of each line displayed on the screen as like below

C:\>set a=Checking

C:\>set a=Checking

C:\>set a=Checking

Etc..

Thanks
Needed fixing, I think. Try this. "delims==" selects the whole line (i.e. the delimiters are the start and end)

Code: [Select]@echo off
for /f "delims==" %%a in (yourfile.txt) do set lastline=%%a
echo %lastline%
Works now. Thanks for your help, it is much appreciated



Discussion

No Comment Found