小编Ram*_*mil的帖子

Powershell 将两个空行替换为一个

我生成的文本文件在每个文本块之间有 2 个空行。我可以使用 Notepad++ 将 \r\n\r\n 替换为 \r\n 来完成此操作,但必须有一种方法可以自动执行此操作。

我尝试在 Powershell 中想出一些办法,但到目前为止还没有任何效果。

这是我到目前为止所尝试过的:

(Get-Content .\test.txt).Replace("\n\n",'\n') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("\s+\r\n+",'\r\n') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("\r\n+",'') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("\n+",'') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("\r\n\r\n",'\r\n') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("^(\s+\r\n)",'\r\n') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("^(\s+\r\n+)",'\r\n') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("^(\r\n+)",'\r\n') | Set-Content .\test.txt
(Get-Content .\test.txt).Replace("\r\n",'\b') | Set-Content .\test.txt
Run Code Online (Sandbox Code Playgroud)

powershell replace

4
推荐指数
1
解决办法
2561
查看次数

标签 统计

powershell ×1

replace ×1