Теперь это уже немножко офтопик - мне было интересно решить задачу в первоначальной формулировке на powershell:
Код:
$errors = @{}
switch -Regex -CaseSensitive -File 'errors.log' {
'^#.*' {
$section = [System.Collections.Generic.List[String]]$_
continue
}
default {
$section.Add($_)
$errors[$_] += [System.Collections.Generic.List[String]]$section
}
}
$errors.Values | .{begin{$n=0} process{$n++; Add-Content -Path "$n.txt" -Value $_ }}