Batch file to copy last line of several files into one new file
I have a load of logs being generated eac开发者_运维问答h time an app runs, I want the very last line of each to be collated into a file or printed on screen by a batch file. e.g I have a dir with files like log123.log,log124.log,log125.log
That can indeed be done with a Windows batch file, using a for
loop to count the lines:
@echo off
for %%f in (*.log) do (
set /a line_count = -1
for /f %%l in (%%f) do set /a line_count += 1
more +%line_count% %%f
)
If your files do not end with a newline character, you'll have to initialize the line_count
variable to 0
instead of -1
.
You can redirect more
's output to append the results to a file:
more +%line_count% %%f >> your_results_file
精彩评论