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