且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Powershell 中替换多行

更新时间:2023-01-14 14:21:39

我决定发布这个 Batch 文件解决方案的原因如下:

I decided to post this Batch file solution for the following reasons:

  • 原始问题batch-file 标签.
  • 最后一个 OP 的评论表明他想从 .bat 文件中运行代码.
  • 这些要点是由我解释",因为解决此问题的***方法是将所有代码保存在一个 Batch .bat 文件中.
  • The original question had the batch-file tag.
  • The last OP's comment indicate that he wants to run the code from a .bat file.
  • These points are "interpreted by me" as the best solution for this problem is to keep all the code in a single Batch .bat file.

.

@if (@CodeSection == @Batch) @then

@echo off
cscript //nologo //E:JScript "%~F0" < file.jnlp > file2.jnlp
goto :EOF

@end

// JScript section

WScript.Stdout.Write(WScript.Stdin.ReadAll().replace(
        /(ruta_logo)|(ruta_xsl)|(url_msg)|(url_forest)|(nombre_entidad)|(url_word)/g,
function (o,A,B,C,D,E,F)
{return ["logo/logo.png","logo/xsl.xsl","url+msg","url+forest","Nombre","Word.exe"]
        [[].concat(A,B,C,D,E,F).join().indexOf(o)] }));

作为一个额外的好处,这个解决方案应该比 PowerShell 运行得更快(恕我直言,它也更简单).

As an additional benefit, this solution should run faster than the PowerShell one (and IMHO it is simpler also).