![Windows PowerShell における Unix cat -e アナログとは何ですか?](https://rvso.com/image/1641910/Windows%20PowerShell%20%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%20Unix%20cat%20-e%20%E3%82%A2%E3%83%8A%E3%83%AD%E3%82%B0%E3%81%A8%E3%81%AF%E4%BD%95%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
私は 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$
#>