Script to extract lines from a large text file

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Yadav Manoj Yadav Manoj 1 year, 4 months ago.

  • Author
  • #26557
    Profile photo of Yadav Manoj
    Yadav Manoj


    I am trying to extract some lines from a huge text file using a powershell script. Wondering if anyone can help me in doing that.

    I have a huge file with all the system events and trying to extract all those lines/events which have the ip "" in them.

    This is what I have till now:

    $log = get-content D:\scripts\iis.log
    foreach ($line in $log){

    Please help.

    Thank you.

  • #26559
    Profile photo of Daniel Krebs
    Daniel Krebs

    Try Select-String -Path D:\scripts\iis.log -Pattern '' -SimpleMatch

    Above cmdlet will return objects to the pipeline matching the lines and other details (line number, etc.)

  • #26561
    Profile photo of Yadav Manoj
    Yadav Manoj

    Thank you very much. I tried it but I got this error:

    The string starting:
    At D:\scripts\Script.ps1:1 char:60
    + Select-String -Path D:\Scripts\iis.log -Pattern" < is missing the terminator: ". At D:\scripts\Script.ps1:1 char:73 + Select-String -Path D:\Scripts\iis.log -Pattern""- + CategoryInfo : ParserError: (-SimpleMatch:String + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

You must be logged in to reply to this topic.