且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 PowerShell 从文本文件中的行尾删除空格

更新时间:2022-02-22 09:33:32

有很多方法,但这个很简单:

There are a number of approaches but this one is pretty simple:

$content = Get-Content file.txt
$content | Foreach {$_.TrimEnd()} | Set-Content file.txt

您可能需要调整 Set-Content cmdlet 上的 Encoding 参数,以获得所需编码(Unicode、ASCII、UTF8 等)的文件输出.

You may need to tweak the Encoding parameter on the Set-Content cmdlet to get the file output in the encoding you want (Unicode, ASCII, UTF8, etc).