I'm trying to access a log file which is 55GB and will not open in any editor. I'm trying to get the last 1000 lines from the log using power shell. I'm new to powershell and any help in doing this is greatly appreciated.
3 Answers
The PowerShell Community Extensions has Get-FileTail:
Get-FileTail -Path foo.txt -Count 1000
Comments
Does this help?
Get-Content '\directory\to\your\log.txt' | Select-Object -last 1000
Get-Content loads all the info from log.txt into memory, this is then passed to Select-Object which will return you the last 1000 items, in this case it will return the last 1000 lines of text.
Hope this helps.
4 Comments
user2470170
Hi thanks for the response. The returned logs have incorrect time stamps on them. Can we narrow it down a bit more.
Kyle Muir
Not a problem, glad I could help. Please mark this answer as the correct answer if it did solve your problem.
Victor Zakharov
Will it not load all 55GB into memory first, go through all records and then keep the last 1000?
Kyle Muir
Yes, I think it will. I aimed my answer for powershell 2.0, I can't think of a better way of doing it.