如何使用 PowerShell 从文本文件中的行尾删除空格 [英] How to use PowerShell to remove space from the end of a line in a text file

查看:85
本文介绍了如何使用 PowerShell 从文本文件中的行尾删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个问题中找到了一个查找和替换文本答案.

I found a find-and-replace text answer from another question.

如何使用 PowerShell 删除文本文件行尾的多余空格?

How do I use PowerShell to remove extra spaces at end of line in a text file?

推荐答案

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

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).

这篇关于如何使用 PowerShell 从文本文件中的行尾删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆