[英]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"}
我希望能够通过windows 命令行来完成。 所以基本上我想做找到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.