windows: bat file to 'tail' last 50 lines of a file

Hi Experts,

How can I keep only the 50 last lines of a file (maximum, could be less if file is small) and output those to a new file?
It can't have any 3rd party help, since this needs to happen on many servers of which I am not admin.

Thanks very much.
W.



Powershell v2:



Powershell v2:



Try if this is fast enough:



You could try this batch file



This is my way of doing TAIL in batch.... this one is bit like last two but uses FIND command to count lines then show last 50 using more, if lines <50 then show whole file... saves looping through the file a line at a time with batch... save it as tail.cmd for instance:
http://scripts.dragon-it.co.uk/links/batch-bottom-footer-lines



Thanks all of you.
Can you make it happen that the tail.cmd is called from another script with the filename as parameter?

Share this

Related Posts

There was an error in this gadget