search a file for multiple strings and output to another file

I am formatting a mail header using the following

get-childitem -Path C:\SearchMe.txt | Select-String -Pattern ‘X-[SB]’, ‘X-Envelope-From’, ‘X-MS-Exchange-Organization-[SP]CL’, ‘Message-’, ‘MIME_H’, ‘Subject:’, ‘score=’,‘Received: from [0-9]’ -Context 0,2 | foreach{$_.line} > C:\stuffit.txt

very thing works great but the ‘Received: from [0-9]’ -Context 0,2

Pretty please help get the context to work or me strip the nasty path up to the last colon

Thank you Very much

John

Why do you use “[0,9]” in “‘Received: from [0-9]’”?

Thank you Ondrej Z


Internet Header BEFORE Cleanup


there are several lines in the before file that start “Received: from” and a alpha charcter
Received: from ALNEXHTCAS01.company.xyz (5.5.5.5) by…
Received: from ALNMSW01.company.xyz (10.241.0.145) by…
Received: from ALNMSW01.company.xyz (10.241.0.145) by…
Received: by 089…
I am only interested in the string
Received: from and some number so the mask and the next two lines after so I use the pattern
‘Received: from [0-9]’ -context 0,2
^^^^i want the line that begins “Received: from next character any number [0-9]”

  • context 0 no lines before the match 2 two lines after the match
    foreach{$_.line} seems to strip the two after the match