Parse logs with Powershell
Parse logs with Powershell
$path = “C:\IISLogs\”
$infile = “alllogs.txt”
$outfile = “parsed.txt”
$batch = 1000
[regex]$match_regex = ‘StringToFindInLogs’
[regex]$replace_regex = ‘BINGO’
$header_line = (Select-String -Path $path\$infile -Pattern $match_regex -list).line
[regex]$header_regex = [regex]::escape($header_line)
#$header_line.trim(‘|’) | Set-Content $path\$outfile
Get-Content $path\$infile -ReadCount $batch |
ForEach {
$_ -match $match_regex -NotMatch $header_regex -Replace $replace_regex ,’$1′ | Out-File $path\$outfile -Append
}