Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如果存在特定单词,则批处理文件以替换整行_Batch File_Replace - Fatal编程技术网

Batch file 如果存在特定单词,则批处理文件以替换整行

Batch file 如果存在特定单词,则批处理文件以替换整行,batch-file,replace,Batch File,Replace,我有一个像这样的文件 //output:One line,file info always -hF1 +ffn -"format=%(%f %l%): Error -> %t %n %m" //Do not break lines -width(0,0) 我想做的是从文本文件中读取一个文本,并用另一行替换搜索文本所在的完整行 例如: 上述文件的输出应该如下 //output:One line,file info always -hF1 +ffn //Se

我有一个像这样的文件

//output:One line,file info always
-hF1
+ffn
-"format=%(%f %l%): Error -> %t %n %m"

//Do not break lines
-width(0,0)
我想做的是从文本文件中读取一个文本,并用另一行替换搜索文本所在的完整行

例如: 上述文件的输出应该如下

    //output:One line,file info always
    -hF1
    +ffn
    //See below line is changed
    -"format=<message><file>%f</file> <line>%l</line> <type>%t</type> <code>%n</code> <desc>%m</desc></message>"<desc>%m</desc></message>"

    //Do not break lines
    -width(0,0)

在这里,我在文本文件中搜索了单词“format”,并替换了完整的一行。

使用此批处理文件:repl.bat- 这个命令在这里起作用。input.txt和output.txt是文件,\x22表示一个引号。顺便说一句,replace命令的引号不平衡。正在搜索的字符串位于行中的任何位置

type input.txt|repl "^.*format=.*" "-\x22format=<message><file>%f</file> <line>%l</line> <type>%t</type> <code>%n</code> <desc>%m</desc></message>\x22<desc>%m</desc></message>\x22" mx >output.txt