Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

At First: Please excuse for my bad english

I´m Searching for a String called "Please try again later" in a Textfile. Can someone tell me, 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
------

Thanks! Daniel

share|improve this question
    
Thanks for Editing C.B.! –  Daniel4711 Aug 5 '13 at 9:52

1 Answer 1

up vote 4 down vote accepted

Like this?

get-content "File.txt" | select-string -Pattern 'Later' -CaseSensitive -Context 2
share|improve this answer
    
It is really awesome parameter. Why I didn't know it before –  Garath Aug 5 '13 at 9:57
    
@Garath Because you don't spend time with get-help get-content -full ;) –  CB. Aug 5 '13 at 10:05
    
This is embarrassing now, I have not read the manual. Thank you! –  Daniel4711 Aug 5 '13 at 10:14
    
@Daniel4711 Glad to help! –  CB. Aug 5 '13 at 10:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.