search a file for multiple strings and output to another file

This topic contains 2 replies, has 2 voices, and was last updated by  Darth kitty 3 years, 9 months ago.

  • Author
  • #18842

    Darth kitty

    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


  • #18860

    Ondrej Zilinec

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

  • #18875

    Darth kitty

    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 ( by...
    Received: from ( by...
    Received: from ( 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.