1

I´m searching for a string called "Please try again later" in a textfile.

How i can export the line with the match including n lines before the matching line?

Currently I use the following command to extract the matching line.

get-content "File.txt | select-string "Later"

Output should be like this (including ------------ if possible)

------
Sending: 250 <[email protected]>
SMTP Command: R-CPT TO:<[email protected]>
Sending: 451 Please try again later
------
1
  • Thanks for Editing C.B.! Commented Aug 5, 2013 at 9:52

1 Answer 1

5

Like this?

get-content "File.txt" | select-string -Pattern 'Later' -CaseSensitive -Context 2
Sign up to request clarification or add additional context in comments.

3 Comments

It is really awesome parameter. Why I didn't know it before
@Garath Because you don't spend time with get-help get-content -full ;)
This is embarrassing now, I have not read the manual. Thank you!

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.