powershell:文章の分割
差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
powershell:文章の分割 [2023/09/01 09:52] – 作成 119.231.18.70 | powershell:文章の分割 [2023/09/01 11:30] (現在) – 119.231.18.70 | ||
---|---|---|---|
行 25: | 行 25: | ||
finally { | finally { | ||
$reader.Close() | $reader.Close() | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | $inputFile = " | ||
+ | $outputFile = " | ||
+ | |||
+ | # 行を数えるカウンタ | ||
+ | $lineCounter = 0 | ||
+ | |||
+ | # 出力する行を保持するための変数 | ||
+ | $outputLine = $null | ||
+ | |||
+ | # StreamReaderを使ってファイルを開く | ||
+ | $reader = [System.IO.StreamReader]:: | ||
+ | $writer = [System.IO.StreamWriter]:: | ||
+ | |||
+ | try { | ||
+ | while (-not $reader.EndOfStream) { | ||
+ | $line = $reader.ReadLine() | ||
+ | $lineCounter++ | ||
+ | |||
+ | # 100, | ||
+ | if ($lineCounter % 100000 -eq 0) { | ||
+ | $writer.WriteLine($line) | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | finally { | ||
+ | $reader.Close() | ||
+ | $writer.Close() | ||
+ | } | ||
+ | |||
+ | |||
+ | ーーーー! | ||
+ | $inputFile = " | ||
+ | |||
+ | # 特定の文字列 | ||
+ | $targetString = " | ||
+ | |||
+ | # StreamReaderを使ってファイルを開く | ||
+ | $reader = [System.IO.StreamReader]:: | ||
+ | |||
+ | $skipLines = 0 | ||
+ | |||
+ | try { | ||
+ | while (-not $reader.EndOfStream) { | ||
+ | $line = $reader.ReadLine() | ||
+ | |||
+ | # 文字列で始まる行が見つかった場合 | ||
+ | if ($line.StartsWith($targetString)) { | ||
+ | $skipLines = 1000 | ||
+ | } | ||
+ | |||
+ | # 行をスキップするかどうかを判断 | ||
+ | if ($skipLines -gt 0) { | ||
+ | $skipLines-- | ||
+ | continue | ||
+ | } | ||
+ | |||
+ | # 行の処理や出力 | ||
+ | # この例では、行をコンソールに出力しています。 | ||
+ | # 必要に応じて、この部分を変更してください。 | ||
+ | Write-Output $line | ||
+ | } | ||
+ | } | ||
+ | finally { | ||
+ | $reader.Close() | ||
+ | } | ||
+ | |||
+ | ーーーーー | ||
+ | $inputFile = " | ||
+ | $lineCount = 10000 # 1ファイルあたりの行数 | ||
+ | $counter = 0 | ||
+ | |||
+ | Get-Content $inputFile | ForEach-Object { | ||
+ | Add-Content -Path " | ||
+ | $counter++ | ||
} | } | ||
</ | </ |
powershell/文章の分割.1693561927.txt.gz · 最終更新: 2023/09/01 09:52 by 119.231.18.70