ユーザ用ツール

サイト用ツール


powershell:落書き

差分

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

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
powershell:落書き [2023/09/05 05:38] 133.106.218.227powershell:落書き [2024/05/13 06:50] (現在) 133.106.206.103
行 63: 行 63:
  
 <code> <code>
 +$headers = "Header1", "Header2", "Header3"
 +$arrayWithHeaders = @()
 +
 +# ヘッダーのみを持つオブジェクトを作成
 +$object = New-Object PSCustomObject
 +foreach ($header in $headers) {
 +    $object | Add-Member -NotePropertyName $header -NotePropertyValue $null
 +}
 +
 +$arrayWithHeaders += $object
 +
 +$commaSeparatedValues = "Value1,Value2,Value3", "unkoValueA,ValueB,ValueC", "ValueX,ValueY,ValueZ"
 +
 +foreach ($line in $commaSeparatedValues) {
 +    if (-not ($line -like "unko*")) { 
 +        # 'unko' で始まらない場合の処理
 +        $values = $line -split ","
 +        $object = New-Object PSCustomObject
 +        for ($i = 0; $i -lt $headers.Length; $i++) {
 +            $object | Add-Member -NotePropertyName $headers[$i] -NotePropertyValue $values[$i]
 +        }
 +        $arrayWithHeaders += $object
 +    } else {
 +        # 'unko' で始まる場合の処理 (必要に応じて変更してください)
 +        Write-Host "This line starts with 'unko': $line"
 +    }
 +}
 +
 +$arrayWithHeaders
 +
 </code> </code>
  
  
 <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/落書き.1693892316.txt.gz · 最終更新: 2023/09/05 05:38 by 133.106.218.227

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki