search a file for multiple strings and output to another file

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Darth kitty Darth kitty 2 years, 2 months ago.

  • Author
    Posts
  • #18842
    Profile photo of Darth kitty
    Darth kitty
    Participant

    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

  • #18860
    Profile photo of Ondrej Zilinec
    Ondrej Zilinec
    Participant

    Why do you use "[0,9]" in "'Received: from [0-9]'"?

  • #18875
    Profile photo of Darth kitty
    Darth kitty
    Participant

    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

You must be logged in to reply to this topic.