F
fpschultze
Hello.
Here comes a batch file that shows how to read the last line of a text
file:
=====
@Echo Off
If %1!==! (
Echo Read and display the last line of a text file
Echo.
Echo Syntax: %~n0 filename.txt
Goto :EOF)
If Not Exist %1 (
Echo File not found - %1
Goto :EOF)
SetLocal
::String that will be used to identify the last line
Set
_=vb043527nc502374v520345c7n20345vb7230457c2n305v72b345v02n3v50237cb230b5v
::Copy the file to the temp folder
Copy %1 %temp%.\tmp.tmp >NUL
::Append unique identifier string to the end of the temp file
Echo %_% >> %temp%.\tmp.tmp
:etermine the line number of the last line
For /F "delims=[]" %%a In ('Find /N "%_%" ^< %temp%.\tmp.tmp') Do Set
_=%%a
::Set lastline variable to the line next to last line of the original
file
Set /A _ -= 2
For /F "Tokens=* Skip=%_%" %%A In (%1) Do Set lastline=%%a
::Cleanup
If Exist %temp%.\tmp.tmp Del %temp%.\tmp.tmp
:isplay line
Echo %lastline%
EndLocal
=====
Have fun
Here comes a batch file that shows how to read the last line of a text
file:
=====
@Echo Off
If %1!==! (
Echo Read and display the last line of a text file
Echo.
Echo Syntax: %~n0 filename.txt
Goto :EOF)
If Not Exist %1 (
Echo File not found - %1
Goto :EOF)
SetLocal
::String that will be used to identify the last line
Set
_=vb043527nc502374v520345c7n20345vb7230457c2n305v72b345v02n3v50237cb230b5v
::Copy the file to the temp folder
Copy %1 %temp%.\tmp.tmp >NUL
::Append unique identifier string to the end of the temp file
Echo %_% >> %temp%.\tmp.tmp
:etermine the line number of the last line
For /F "delims=[]" %%a In ('Find /N "%_%" ^< %temp%.\tmp.tmp') Do Set
_=%%a
::Set lastline variable to the line next to last line of the original
file
Set /A _ -= 2
For /F "Tokens=* Skip=%_%" %%A In (%1) Do Set lastline=%%a
::Cleanup
If Exist %temp%.\tmp.tmp Del %temp%.\tmp.tmp
:isplay line
Echo %lastline%
EndLocal
=====
Have fun