powershell - 用新行替换字符

标签 powershell powershell-4.0

Powershell ver 4. Windows 7
我想用文本文件中的新行替换,。我尝试了以下脚本

(Get-Content C:\Test\test.txt).Replace(',','`n') | Set-Content C:\Test\testv2.txt

但是当我看到输出文件时,我看到,被替换为'`n'而不是新行。

我也尝试使用双引号而不是单引号。
Replace(',',"`n")

最佳答案

试试这个:

[IO.File]::ReadAllText(C:\Test\test.txt) -replace ',',"`r`n" | Out-File C:\Test\testv2.txt

P.S.抱歉,现在没有时间解释它。

关于powershell - 用新行替换字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39104275/

相关文章:

powershell - 电源外壳 : A command as a variable with parameter

windows - 在 powershell 脚本中以不同用户身份在本地运行代码块

powershell - 使用replace Mulin Powershell将一个文件的内容写入另一个文件

Powershell ISE 错误地将 openssl.exe 正常输出解释为错误

json - 从JSON提取值

powershell - 使用 Powershell DSC 安装可执行文件

bash - Git 哈希对象在 Powershell、CMD 和 Bash 中产生不同的 SHA1?

powershell - AWS Powershell - 按名称获取 SNS 主题

vba - 从VBA向Powershell提供参数

power-shell 脚本的 Windows 调度不可靠