3

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.

1

3 Answers 3

4

In PowerShell 3 you can the new Tail parameter:

Get-Content file.log -Tail 1000
Sign up to request clarification or add additional context in comments.

Comments

3

The PowerShell Community Extensions has Get-FileTail:

Get-FileTail -Path foo.txt -Count 1000

Comments

2

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

Hi thanks for the response. The returned logs have incorrect time stamps on them. Can we narrow it down a bit more.
Not a problem, glad I could help. Please mark this answer as the correct answer if it did solve your problem.
Will it not load all 55GB into memory first, go through all records and then keep the last 1000?
Yes, I think it will. I aimed my answer for powershell 2.0, I can't think of a better way of doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.