
我使用 Windows 10 Powershell,並且希望查看文件內容,並在每行末尾(換行符之前)列印 $ 字元。
在類 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 cmdlet 來儲存變更或寫入新檔案。
(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$
#>