Select-String
$ $OutputEncoding
でエンコードの状況を見てからやったほうがいい
PowerShellのバージョン次第で、-Encoding Default がSJISじゃなくてUTF8になってることがある。 -Encoding Default =SJISを想定
つまり、この指定でもいい
-Encoding sjis
grepして、別ファイルを生成する
出来た~~
$ Select-String -Pattern '^"202201".*' sample.csv -Encoding Default | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } > new3.txt
ChatGPTに依頼して作ってもらったコマンド
$ Get-ChildItem -Path "C:\Logs" -Recurse | Select-String -Pattern "error" | Select-Object Path,LineNumber,Line | Export-Csv -Path "Results.csv" -NoTypeInformation
文字化けるから訂正してもらったバージョン
$ Get-Content "C:\log.txt" | Select-String "error" | Out-File "C:\result.csv" -Encoding UTF8
$ Get-ChildItem -Path "C:\MyFolder" -Filter *.txt -Recurse | Get-Content
$ Get-Content : パラメーター名 'Recurse' に一致するパラメーターが見つかりません。
$ Get-Date -Format "yyyyMMdd_HHmmss"
これでよかった。。
$ Select-String -Path "index.html" -Pattern 'h3 title.*'