ユーザ用ツール

サイト用ツール


powershell:落書き

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
powershell:落書き [2023/09/05 06:14] 133.106.218.227powershell:落書き [2024/05/13 06:50] (現在) 133.106.206.103
行 97: 行 97:
  
 <code> <code>
 +$file = "C:\path\to\your\largefile.log"
 +
 +$reader = [System.IO.File]::OpenText($file)
 +$count = 0
 +while($reader.ReadLine() -ne $null) {
 +    $count++
 +}
 +$reader.Close()
 +
 +Write-Output "Total lines: $count"
 +
 </code> </code>
  
  
 <code> <code>
 +# 入力ファイルパス
 +$inputPath = "C:\path\to\your\inputfile.txt"
 +# 出力ファイルのベースパス
 +$outputBasePath = "C:\path\to\output\outputfile"
 +
 +# ファイルを開いて読み込む
 +$reader = [System.IO.StreamReader]::new($inputPath)
 +
 +# 変数の初期化
 +$lineCount = 0
 +$fileIndex = 1
 +$content = New-Object System.Collections.Generic.List[string]
 +
 +try {
 +    while ($null -ne ($line = $reader.ReadLine())) {
 +        # 行をリストに追加
 +        $content.Add($line)
 +        $lineCount++
 +
 +        # 10000行ごとにファイルに書き出す
 +        if ($lineCount -eq 10000) {
 +            $outputPath = "$outputBasePath$fileIndex.txt"
 +            [System.IO.File]::WriteAllLines($outputPath, $content)
 +            # 変数をリセット
 +            $content.Clear()
 +            $lineCount = 0
 +            $fileIndex++
 +        }
 +    }
 +
 +    # 最後のファイル(10000行未満の場合)
 +    if ($content.Count -gt 0) {
 +        $outputPath = "$outputBasePath$fileIndex.txt"
 +        [System.IO.File]::WriteAllLines($outputPath, $content)
 +    }
 +}
 +finally {
 +    $reader.Close()
 +}
 +
 </code> </code>
  
powershell/落書き.1693894447.txt.gz · 最終更新: 2023/09/05 06:14 by 133.106.218.227

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki