Author Posts

June 17, 2015 at 4:37 am

Hi,

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 "172.16.2.62" in them.

This is what I have till now:

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

Please help.

Thank you.

June 17, 2015 at 4:46 am

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

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

June 17, 2015 at 5:52 am

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"172.16.2.62 < is missing the terminator: ". At D:\scripts\Script.ps1:1 char:73 + Select-String -Path D:\Scripts\iis.log -Pattern"172.16.2.62"- + CategoryInfo : ParserError: (-SimpleMatch:String + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString