Windows PowerShell における Unix cat -e アナログとは何ですか?

Windows PowerShell における Unix cat -e アナログとは何ですか?

私は Windows 10 Powershell を使用しており、各行の末尾の NEWLINE の前に $ 文字が印刷されたファイルの内容を表示したいと考えています。

UNIX のようなシステムでは、次のように実行できますcat -e file_name。Powershell でも同じ結果が得られますか?

回答をよろしくお願いします。

答え1

私のコメントの続きです。こうすることができます...

元のファイルの内容 ---

Get-Content -Path 'D:\temp\book1.txt'
# Results
<#
Site,Dept
Main,aaa,bbb,ccc
Branch1,ddd,eee,fff
Branch2,ggg,hhh,iii
#>

変更されたファイルの内容 ---

これを使って...

(Get-Content -Path 'D:\temp\book1.txt'  -Raw).Replace("`r", "$")

...またはこれ。

(Get-Content -Path 'D:\temp\book1.txt'  -Raw) -Replace("`r", "$") 

# Results
<#
Site,Dept$ 
 Main,aaa,bbb,ccc$ 
 Branch1,ddd,eee,fff$ 
 Branch2,ggg,hhh,iii$ 
#>

注意点として、変更を保存したり、新しいファイルに書き込んだりするには、Set-Content コマンドレットを使用する必要があります。

(Get-Content -Path 'D:\temp\book1.txt'  -Raw).Replace("`r", "$") | 
Out-File -FilePath 'D:\temp\book1Modified.txt'

Get-Content -Path 'D:\temp\book1Modified.txt'
# Results
<#
Site,Dept$
Main,aaa,bbb,ccc$
Branch1,ddd,eee,fff$
Branch2,ggg,hhh,iii$
#>

関連情報