2013-09-25 74 views
0

一个文本文件中替换文本,而能够安装各种花哨的查找和替换工具,我需要找到并与从Windows Server命令行替换文本文件中的字符串2008与Windows命令行

我会怎么做?

例子:

text.md 

    Hello world! 

更改为:

text.md 

    Hello everyone! 

我在寻找类似:

for /f %%A in (text.md) do (

    set "line=%%A" 

    if defined line (

     // and here the replacement 

    ) ELSE echo. 
) 
+0

平原批量更换有限制,这是什么文字,我们正在处理了解的 - 或者我们可以浪费我们的时间,因为它不会工作。 – foxidrive

回答

0

这工作对我来说:

(for /f "tokens=1,* delims=]" %%A in ('"type text.md|find /n /v """') do (

    set "line=%%B" 
    if defined line (
     call set "line=echo.%%line:world=everyone%%" 
     for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X 
    ) ELSE echo. 

)) >text2.md 

move /Y text2.md text.md 
0

使用repl.bat,你会把路径上(比如在C:\ Windows或添加到路径中的实用程序文件夹)

type "text.md"|repl "world" "everyone" >"text.tmp" 
move /y "text.tmp" "text.md" 

repl.bat是SED般帮手批从文件 - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

findrepl.bat是类似grep的助手批处理文件从 - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697

如果你想简单的批处理技术,那么这将取决于具体任务和文本构成。

+0

谢谢,但恐怕这超出了我的理解范围。 :) – Kriem

+0

看我上面的编辑 – foxidrive

+0

我明白了。我需要将'repl.bat'放在我正在使用的环境中我无法做到的路径中。感谢您的明确解释! – Kriem