I have a rather specialized task I am trying to automate. Each day, someone has to copy 144 each from four different .dat files into an Excel spreadsheet. These .dat files are updated twice daily with new data resulting in the file growing each time. So we copy 144 lines near the bottom of the file with the last line to be copied a known number of lines from the final line in the file. I would like to automate this process. I have determined a way to do this, but I am a novice with coding. I would like to write a script that can copy the 144 lines a specified number of lines (say 22) from the end of the file, and paste into a new text file. I have been able to find some information on copy and pasting the first 100 lines of a text file into a new file (http://www.computing.net/answers/windows-xp/dos-batch-to-copy-first-100-lines-of-a-text-file/202404.html) and some information on displaying the last 10 lines (CMD.EXE batch script to display last 10 lines from a txt file), but I have found nothing that seems like it would work for this.
I have this for copying the last n lines:
@echo OFF
:: Get the number of lines in the file
for /f %%i in ('find /v /c "" ^< test.dat') do set /a lines=%%i
:: Paste last 10 lines
set /a startLine=%lines% - 10
more /e +%startLine% ForneyTEOM.dat > lastLines.txt
echo All Done.
Echo.
Echo Press any key to close this window.
Pause>NUL
EXIT
This doesn't let me take the n lines that end x lines from the end of the file and start x+n lines from the end of the file which is what I want.