Can anyone please advise how to use Windows Command Prompt to read last 10 lines of a text file?
Asked
Active
Viewed 2,699 times
0
-
1Possible duplicate of [How do you loop through each line in a text file using a windows batch file?](https://stackoverflow.com/questions/155932/how-do-you-loop-through-each-line-in-a-text-file-using-a-windows-batch-file) – Stavm Jun 16 '17 at 07:49
-
2Possible duplicate of [CMD.EXE batch script to display last 10 lines from a txt file](https://stackoverflow.com/questions/523181/cmd-exe-batch-script-to-display-last-10-lines-from-a-txt-file) – Compo Jun 16 '17 at 09:31
1 Answers
-1
One way is to use PowerShell.
powershell -NoProfile -Command "Get-Content .\rrreg.ps1 | Select-Object -Last 3"
Iterating across each line can also be done.
FOR /F "usebackq tokens=*" %%s IN (`powershell -NoProfile -Command "Get-Content .\rrreg.ps1 | Select-Object -Last 3"`) DO (
ECHO %%s
)
Of course, having a tail command on your system would make tail -10 thefile.txt possible. How much easier can it be than that?
lit
- 13,209
- 9
- 55
- 92