2013-09-25 76 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