1.

Solve : copying last X lines to new file?

Answer»

I have a log and I need to copy last 50 lines from logfile.txt to lastlines.txt
below script works only if there is more than 50 lines in logfile.txt
if there is les than 50 lines in logfile.txt it MAKES empty file but that is wrong.
script must copy last 50 lines to new file if there is less than 50 lines than it copy what it is in logfile.txt to new file
lastlines.txt
Can SOMEONE help me fix this script?
Code: [Select] for /f %%i in ('find /v /c "" ^< LogFile.txt') do set /a lines=%%i
set /a startLine=%lines% - 50
more /e +%startLine% LogFile.txt > lastLines.txtok I MANAGE to solve this by myself

Code: [Select]for /f %%i in ('find /v /c "" ^< LogFile.txt') do set /a lines=%%i
set /a startLine=%lines% - 50
more /e +%startLine% LogFile.txt > lastLines.txt
for %%x in (lastLines.txt) do if not %%~zx==0  (GOTO End) else (goto A)
:A
xcopy /Y LogFile.txt lastLines.txt
:End



Discussion

No Comment Found