Try this:
$FileName = $null,"c:\junk\Lang1.txt","c:\junk\Lang2.txt","c:\junk\Lang3.txt" # $null is there so the inner loop's $_ can be used without subtracting 1
# Remove any old files
1..3 |
ForEach-Object{
Remove-Item $FileName[$_] -ErrorAction SilentlyContinue
}
Get-ChildItem c:\junk\l.txt |
Select-String -Pattern "^\d\d\d$" -Context 0,4 |
ForEach-Object{
$x = $_
1..3 | ForEach-Object{
$x.Line | Out-File $FileName[$_] -Append
$x.Context.PostContext[0] | Out-File $FileName[$_] -Append # timestamp?
$x.Context.PostContext[$_] |Out-File $FileName[$_] -Append # text
"" |Out-File $FileName[$_] -Append # blank line
}
}