UPDATE: Article changed based on the comment from Mr. Sewell.
I wrote recently about making a HEAD utility to find the top few lines from a text file. I used Powershell and scripting to make this work from any Windows command line on my machine.
Someone asked about TAIL, which is easy, so I did this as well and set up a tail utility.
Get-Content in Powershell will do this, so I took my head.cmd and did a save as in VS Code.
Then I changed the “first” in the code to “last”, as shown here.
UPDATE: Based on a comment from Mr. Sewell, I updated the code.
There is a tail parameter for Get-Content, so let’s use that.
powershell "get-content %1 -tail 10 | select-object"
This gets me the end of a file. As an example this is below. Here’s a text file I have with various values. As you can see below, the bottom values are zeros.
Here’s my tail utility working:
UPDATE: I left the original piece below in italics, but with the tail parameter, this takes a few seconds.
If I run this on a larger, 1.5GB file, it takes a few seconds.
In case you’re wondering how this works on larger files, it can be slow. This took 3 minutes on my machine to get the last ten lines of a 1.5GB file.
Get-Content $file -Tail 10 will be much quicker
Get-Content $file -TotalCount 10 will be much quicker for the first 10 lines
Both are in the region of 5 milliseconds for a 1.5 Gb file
Thanks, Rob. updated both articles.