i\'m reading a lot of threads - but nothing for me personal. I need to split text file in the following form:
--------------------- Instance Type and Transm
Something like this should work:
$InputFile = "c:\path\myfiletosplit.txt"
$Reader = New-Object System.IO.StreamReader($InputFile)
$a = 1
While (($Line = $Reader.ReadLine()) -ne $null) {
If ($Line -match "--------------------- Instance Type and Transmission --------------") {
$OutputFile = "MySplittedFileNumber$a.txt"
$a++
}
Add-Content $OutputFile $Line
}
or whitout .net class:
$a = 1
gc "c:\path\myfiletosplit.txt" | % {
If ($_ -match "--------------------- Instance Type and Transmission --------------") {
$OutputFile = "MySplittedFileNumber$a.txt"
$a++
}
Add-Content $OutputFile $_
}