2013-07-10 25 views
0

我有一個像批處理文件來替換整個行,如果特定的詞存在

//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) 

在這裏,我搜索了在文本文件中單詞'格式」,並更換了整條生產線。

回答

0

使用此批處理文件:repl.bat - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855 此命令在此處起作用。 input.txt和output.txt是文件,\ x22代表一個引號。順便說一句,你的替換命令有不平衡的引號。正在搜索的字符串是format=行中的任意位置。

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 
相關問題