Probably best if you download a free utility like
sed for Windows.
Windows batch is pretty lousy at processing text files. But if you want to use pure batch without a utility like sed, it can be done.
Option 1 (untested)
I think this is the fastest pure batch option. It should work as long as the source file lines are terminated with <CR><LF> (Windows style) and not simply <LF> (Unix style)
Code: Select all
@echo off
setlocal enableDelayedExpansion
set source_file="index.php"
set name_list_file="filenames.txt"
set "rename=word"
for /f %%n in ('type %source_file%^|find /c /v ""') do set len=%%n
for /f "usebackq delims=," %%G in (%name_list_file%) do <%source_file% (
for /l %%l in (1 1 %len%) do (
set "line="
set /p "line="
if defined line (
echo(!line:%rename%=%%G!
) else echo(
)
)>%%G
Option 2 (untested)
This is slower, especially if the source file is large. But it should work with both Windows and Unix style lines.
Code: Select all
@echo off
setlocal disableDelayedExpansion
set source_file="index.php"
set name_list_file="filenames.txt"
set "rename=word"
for /f "usebackq delims=," %%G in (%name_list_file%) do (
for /f "tokens=*" %%a in ('find /n /v "" %source_file%') do (
set "line=%%a"
setlocal enableDelayedExpansion
set line=!line:*]=!
if defined line (
echo(!line:%rename%=%%G!
) else echo(
endlocal
)
)>%%G
Dave Benham