gpt4 book ai didi

windows - 在 Windows 批处理中使用 PowerShell 命令和反引号换行符

转载 作者:可可西里 更新时间:2023-11-01 10:14:05 26 4
gpt4 key购买 nike

我正在尝试编写一个 Windows 批处理文件,它将用中间的换行符替换出现的尖括号 (><)。

我是 PowerShell 的新手,但在搜索可能的解决方案时,我发现了 PowerShell 的以下作品:

(get-content input.txt) -replace "><", ">`n<"  | set-content output.txt

要在 Windows 批处理中使用它,我需要将它包装在里面

    powershell -command "arguments"

所以最后的命令是这样的:

powershell -command "(gc input.txt) -replace '><', '>`n<'  | sc output.txt"

但是,这当然行不通,因为替换文本周围的单引号会导致重音引号转义字符按字面意思处理。

我广泛搜索了用于识别 PowerShell 转义字符的转义字符的正确组合,并找到了类似的答案 in here ,但是当我尝试这个建议时,我得到一个“<此时是意外的”错误。我认为我需要的更复杂,因为我的搜索字符串还包含尖括号。

最佳答案

查看 powershell.exe 命令行选项。您可以使用脚本 block :

powershell -command {(gc input.txt) -replace "><", ">`n<"  | sc output.txt}

关于windows - 在 Windows 批处理中使用 PowerShell 命令和反引号换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47193850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com