问题描述
所需的输出是将所有 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"