ユーザ用ツール

サイト用ツール


powershell:落書き2

差分

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

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
powershell:落書き2 [2024/05/13 04:37] 133.106.206.103powershell:落書き2 [2024/05/13 05:13] (現在) 133.106.206.103
行 75: 行 75:
     $_.Substring(0, [math]::Min(30, $_.Length))     $_.Substring(0, [math]::Min(30, $_.Length))
 } | Set-Content $outputPath } | Set-Content $outputPath
 +
 +
 +
 +# 入力ファイルと出力ファイルのパスを設定
 +$inputPath = "C:\path\to\input.txt"
 +$outputPath = "C:\path\to\output.txt"
 +
 +# 出力ファイルが既に存在する場合は削除
 +if (Test-Path $outputPath) {
 +    Remove-Item $outputPath
 +}
 +
 +# 前の行を記録する変数
 +$previousLine = $null
 +
 +# 入力ファイルを読み込み、各行の最初の30文字を取得し、連続する重複行を排除して出力ファイルに書き込む
 +Get-Content $inputPath | ForEach-Object {
 +    $currentLine = $_.Substring(0, [math]::Min(30, $_.Length))
 +    if ($currentLine -ne $previousLine) {
 +        $currentLine
 +    }
 +    $previousLine = $currentLine
 +} | Set-Content $outputPath
 +
 </code> </code>
powershell/落書き2.txt · 最終更新: 2024/05/13 05:13 by 133.106.206.103

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki