我正在运行以下powershell命令:
powershell -Command "(gc myfile1.json) -replace '1.7976931348623157E308', '""-Infinity""' | Out-File myFile.json"
powershell -Command "(gc myfile1.json) -replace '4.9E-324', '""-Infinity""' | Out-File myFile.json"
我在我的outputfile中获得无限,但我希望它被双重引用 ->" infinity"
我应该如何处理?我尝试使用以下逃脱的char:`但是我必须错过一些东西,因为这也不起作用。
非常感谢您的帮助。
如果您用外部双引号将powershell命令包裹起来:
- 必须逃脱内部双引号,因为否则cmd.exe会偶然发现管道符号 - 解释它们本身。
- 同时,您可以使用一个
-replace
正则判断性替代品交替
powershell -NoP -C "(gc myfile1.json) -replace '4.9E-324|1.7976931348623157E308', '"-Infinity"' | Out-File myFile.json"
另外,您可以省略外部双引号,但必须用套筒逃脱管道符号。
powershell -NoP -C (gc myfile1.json) -replace '4.9E-324^|1.7976931348623157E308', '"-Infinity"' ^|Out-File myFile.json
这是因为它是命令参数中的字符串作为字符串,您必须添加一个easpe的级别:
powershell -Command "(gc d:test.txt) -replace 'x','""y""' | out-file D:result.txt"
编辑:语法荧光笔不喜欢它,但是语法是正确的。