My goal is to add text after the match. Howerve; the code below doesn't do anything. Apreciate your help.
Example:
Text before:
192.1.2.41 - - [09/Nov/2013:00:13:00]
10.32.1.52 - - [09/Nov/2013:00:13:00]
192.1.2.41 - - [09/Nov/2013:00:13:00]
178.19.3.39 - - [09/Nov/2013:00:13:00]
10.2.91.52 - - [09/Nov/2013:00:13:00]
10.2.91.52 - - [09/Nov/2013:00:13:00]
Text After:
192.1.2.41 - - [09/Nov/2013:00:13:00]
10.2.91.52 localhost - - [09/Nov/2013:00:13:00]
192.1.2.41 - - [09/Nov/2013:00:13:00]
178.19.3.39 - - [09/Nov/2013:00:13:00]
10.2.91.52 - - [09/Nov/2013:00:13:00]
10.2.91.52 - - [09/Nov/2013:00:13:00]
code:
$fileName = "C:\scripts\access_combined.log"
[regex]$pattern='10\.2\.91\.52'
(Get-Content $fileName) | Foreach-Object {
$_
if ($_ -match $pattern)
{
#add text aftre match
$_ += "localhost"
}
} | Set-Content $fileName