0

For exemple, I have the following file:

...
Thu Sep 24 15:08:21 2019
SMON: enabling cache recovery
Archived Log entry 22 added for thread 1 sequence 27 ID 0xedf06523 dest 1:
Thu Sep 25 13:08:45 2019
CJQ0 started with pid=33, OS id=316
Thu Sep 26 15:13:45 2019
Starting background process SMCO
Thu Sep 26 15:13:45 2019
SMCO started with pid=19, OS id=2340
...

I need to read from my current day Thu Sep 26 13:08:45 2019.

I made this, but it bring only the lines with the date.

Get-Content $alertlog | Select-String $(Get-Date -Format "ddd MMM dd")

The result:

Thu Sep 26 15:13:45 2019
Thu Sep 26 15:13:45 2019

What I need:

Thu Sep 26 15:13:45 2019
Starting background process SMCO
Thu Sep 26 15:13:45 2019
SMCO started with pid=19, OS id=2340
...

1 Answer 1

3

Just add the -Context Parameter

Get-Content $alertlog|select-string $(Get-Date -format "ddd MMM dd")  -Context 0,1
Sign up to request clarification or add additional context in comments.

3 Comments

Great, verry simple!
Isn't necessary in my case, but if I wanted to read from a specified string until other string? it's possible?
@DaniloNeto It's possible, but not via -Context.

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.