如何解决如何使用 powershell 命令用新行替换字符串?从批处理文件中? -双引号问题
所需的输出是将所有 5 个波浪号转换为换行符。
命令是
Powershell (Get-Content -Raw allactsconv.txt) "-replace '~~~~~',"[\r\n]" | Out-File -FilePath allactsconv.txt -Force -Encoding ascii"
它回来了
At line:1 char:55
+ (Get-Content -Raw allactsconv.txt) -replace '~~~~~',[\r\n] | Out-Fil ...
+ ~
Missing type name after '['.
At line:1 char:53
+ (Get-Content -Raw allactsconv.txt) -replace '~~~~~',[\r\n] | Out-Fil ...
+ ~
Missing expression after ','.
At line:1 char:54
+ (Get-Content -Raw allactsconv.txt) -replace '~~~~~',[\r\n] | Out-Fil ...
+ ~~~~~~
Unexpected token '[\r\n]' in expression or statement.
+ CategoryInfo : ParserError: (:) [],ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingTypename
我认为问题可能出在方括号上,但没有它们,错误完全相同。
更好的解决方案是将整个批处理文件(它做了很多其他的事情)重写为一个 powershell 脚本,但不幸的是我现在需要解决这个问题。在某个时候,我会这样做。
看起来问题是双引号内的双引号,但我该如何解决?如果可以,我想使用 powershell 命令,因为我需要学习它。
解决方法
纯粹基于您表示要替换并希望替换的字符串,我将提供以下选项:
{json.data && <h1>{json.data.email}</h1>}
如果您更喜欢在 PowerShell 中使用单引号,(不是我的偏好),那么:
Powershell -NoProfile "(Get-Content -Raw \".\allactsconv.txt\") -Replace \"~~~~~\",\"[`r`n]\" | Out-File -FilePath \".\allactsconv.txt\" -Force -Encoding ASCII"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。