繁体   English   中英

是否可以通过 windows 命令行用换行符替换文本文件中的字符串?

[英]Is it possible to replace a string in a text file with a line break via the windows command line?

我有一个,其中包含一行数据,没有任何 它将包含与此类似的数据:

{"Id":1801157,":"33611134":"E","Oct 19:":"G","Order":"117" ,"BroadcastDate":"2019-10-19"}

我想要做的是在BroadcastDate之前插入一个换行符,所以它现在看起来像这样:

{"Id":1801157,":"33611134":"E","Oct 19:":"G","Order":"117" ,"
BroadcastDate":"2019-10-19"}

我希望能够通过 来完成。 所以基本上我想做找到BroadcastDate并用<line break>BroadcastDate替换它。

似乎是一件奇怪的事情,但在 PowerShell 中并不是很难。 如果您在受支持的 Windows 系统上,它将具有 PowerShell。

=== 格式-BroadcastFile.ps1

Get-Content -Path '.\BroadcastDate.txt' |
    ForEach-Object {
        $_ -replace 'BroadcastDate'."`nBroadcastDate"
    }

=== 在 .bat 文件脚本或 cmd shell 中运行它。

powershell -NoLogo -NoProfile -File "Format-BroadcastFile.ps1" >".\newfile.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM