私はたくさんのスレッドを読んでいますが、個人的なものは何もありません。次の形式でテキスト ファイルを分割する必要があります。
--------------------- Instance Type and Transmission --------------
...text..
...text..
--------------------------- Message Trailer ------------------------
...text...
...text...
--------------------- Instance Type and Transmission --------------
...text..
...text..
コンテンツを行ごとに分割------------- Instance Type and Transmission --------------
し、新しいファイルで間にテキストを出力します。
このような:
ファイル1:
--------------------- Instance Type and Transmission --------------
...text..
...text..
--------------------------- Message Trailer ------------------------
...text...
...text...
ファイル 2:
--------------------- Instance Type and Transmission --------------
...text..
...text..
Perl と awk はこれを非常に簡単に行います。いくつかの例を見つけましたが、powershell には何もなく、サイズ分割によるテキスト ファイルのみでした。
@CB に感謝します。複数のファイルに有効なこのソリューションで終了しました。
$InPC = "C:\Scripts"
Get-ChildItem -Path $InPC -Filter *.txt | ForEach-Object -Process {
$basename= $_.BaseName
$m = ( ( Get-Content $_.FullName | Where { $_ | Select-String "--------------------- Instance Type and Transmission --------------" -Quiet } | Measure-Object | ForEach-Object { $_.Count } ) -ge 2)
$a = 1
if ($m) {
Get-Content $_.FullName | % {
If ($_ -match "--------------------- Instance Type and Transmission --------------") {
$OutputFile = "$InPC\$basename _$a.txt"
$a++
}
Add-Content $OutputFile $_
}
Remove-Item $_.FullName
}
}