| 1. |
Solve : TOUGH!replace text in file where text like hello*? |
|
Answer» Hello 1.search all files in c:\ and its subdir with the name text.txt set pathToDirs=c:\test 'dir "test.txt" %pathToDirs% /s/b' This may work a LITTLE better but Ghostdog is right. Batch code is not a programming language and data manipulation is easier is any of free Windows scripting languages VBScript, JScript, Python, Rexx, etc. Code: [Select]setlocal enabledelayedexpansion set pathToDirs=c: set tmpfile=%TMP%\abc.123.aux if exist %tmpfile% del %tmpfile% for /f %%d in ('dir %pathToDirs%\test.txt /a:-d /s /b') do ( call :REPLACE_TEXT %%d hello goodbye ) goto :eof :REPLACE_TEXT for /f "delims=" %%x in (%1) do ( set tmp=%%x set tmp=!tmp:%2=%3! echo !tmp! >> %tmpfile% ) move /y %tmpfile% %1 > NUL Good luck. 8-)Quote if the string is "greet=hello" i don't want to change it. setlocal enabledelayedexpansion set pathToDirs=c: set tmpfile=%TMP%\abc.123.aux if exist %tmpfile% del %tmpfile% for /f %%d in ('dir %pathToDirs%\test.txt /a:-d /s /b') do ( call :REPLACE_TEXT %%d [highlight]"greeting=hello" "greeting=goodbye"[/highlight] ) goto :eof :REPLACE_TEXT for /f "delims=" %%x in (%1) do ( set tmp=%%x set tmp=!tmp:%[highlight]~[/highlight]2=%[highlight]~[/highlight]3! echo !tmp! >> %tmpfile% ) move /y %tmpfile% %1 > NUL [/b] Have fun |
|