LoginSignup
0
0

More than 1 year has passed since last update.

WindowsPowerShellでUTF8-BOMLessでLFなファイルを出力する

Last updated at Posted at 2022-05-02

WindowsPowerShellOut-Fileコマンドレットで下記のようにエンコーディングをUTF8を指定してファイル出力した場合。

BOM付きUTF8でファイルが出力されます。

# UTF8-BOM CRLF
@("Hello World","Foo Bar") | Out-File -FilePath c:\temp\utf8-bom-crlf.txt -Encoding utf8

image.png

今回、WindowsPowerShellでコマンドの処理結果をBOMLessかつ改行コードLFでファイルを出力したいケースがあったので方法をメモ。

# UTF8-BOMLess LF
@("Hello World","Foo Bar") | %{ $_+"`n" } | ForEach-Object{ [Text.Encoding]::UTF8.GetBytes($_) } | Set-Content -Encoding Byte -Path c:\temp\utf8-bomless-lf.txt

image.png

参考サイト

PowerShellでBOM無しUTF8を簡単に扱う、デフォルト設定を簡単に変える方法

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0